replace sha256 with pedersen_hash in get_key (#46)

* replace sha256 with pedersen_hash

* fix: prevent an OOB

* workaround timeout in unit test

* update go-ipa and reduce the timeout

* fix for unit tests: do not call NewAccessWitness in NewEVMTxContext (#49)

* potential fix: do not call NewAccessWitness in NewEVMTxContext

* more fixes: check for the existence of Accesses

* fix absence of witness in copy

* fix another witness issue

* workaround: ensure the prefetcher is off in verkle mode

* fix the remaining issues in tests

* review feedback

* fix witness allocation in stateless test
This commit is contained in:
Guillaume Ballet
2022-01-07 11:53:48 +01:00
committed by GitHub
parent f215cc0791
commit e16e9cc84b
8 changed files with 48 additions and 31 deletions

View File

@ -17,7 +17,9 @@
package utils
import (
"crypto/sha256"
"github.com/crate-crypto/go-ipa/bandersnatch/fr"
"github.com/crate-crypto/go-ipa/ipa"
"github.com/gballet/go-verkle"
"github.com/holiman/uint256"
)
@ -40,15 +42,23 @@ var (
)
func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte {
digest := sha256.New()
digest.Write(address)
treeIndexBytes := treeIndex.Bytes()
var payload [32]byte
copy(payload[:len(treeIndexBytes)], treeIndexBytes)
digest.Write(payload[:])
h := digest.Sum(nil)
h[31] = subIndex
return h
var poly [256]fr.Element
verkle.FromLEBytes(&poly[0], []byte{1})
verkle.FromLEBytes(&poly[0], []byte{2, 63})
verkle.FromLEBytes(&poly[1], address[:16])
verkle.FromLEBytes(&poly[2], address[16:])
var index [32]byte
copy(index[:], treeIndex.Bytes())
verkle.FromLEBytes(&poly[3], index[:16])
verkle.FromLEBytes(&poly[4], index[16:])
for i := 5; i < len(poly); i++ {
verkle.CopyFr(&poly[i], &verkle.FrZero)
}
ret := ipa.NewIPASettings().Commit(poly[:])
retb := ret.Bytes()
return retb[:]
}
func GetTreeKeyAccountLeaf(address []byte, leaf byte) []byte {