go-ethereum/crypto/poseidon/codehash_test.go
Péter Garamvölgyi 304af60f50
feat: change bytecode hash function from Keccak to Poseidon (#149)
* feat: change bytecode hash function from Keccak to Poseidon

* fix TestStateProcessorErrors

* rename files

* copy iden3's poseidon package to local

* update poseidon hash

* apply new hash in codehash

* extend hash method, use actual code size as cap

* prune keccak(nil) for empty code

* update empty code hash references to Poseidon

* add TestPoseidonCodeHash

* use keccak for empty code hash

* go mod tidy

* goimports

* use Poseidon code hash in state and sync tests

* run goimports

* run goimports

* remove unnecessary reallocation from CodeHash

* goimports

* move codehash API to separate module

* add missing package

* fix review comments

* improve comments

Co-authored-by: Ho Vei <noelwei@gmail.com>
2022-09-08 06:16:17 +08:00

24 lines
489 B
Go

package poseidon
import (
"fmt"
"testing"
)
func TestPoseidonCodeHash(t *testing.T) {
// nil
got := fmt.Sprintf("%s", CodeHash(nil))
want := "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
if got != want {
t.Errorf("got %q, wanted %q", got, want)
}
// single byte
got = fmt.Sprintf("%s", CodeHash([]byte{0}))
want = "0x0ee069e6aa796ef0e46cbd51d10468393d443a00f5affe72898d9ab62e335e16"
if got != want {
t.Errorf("got %q, wanted %q", got, want)
}
}