1313)
1414
1515type ProofNode interface {
16- Hash (hash hashFunc ) * felt.Felt
16+ Hash (hash HashFunc ) * felt.Felt
1717 Len () uint8
1818 PrettyPrint ()
1919}
@@ -23,7 +23,7 @@ type Binary struct {
2323 RightHash * felt.Felt
2424}
2525
26- func (b * Binary ) Hash (hash hashFunc ) * felt.Felt {
26+ func (b * Binary ) Hash (hash HashFunc ) * felt.Felt {
2727 return hash (b .LeftHash , b .RightHash )
2828}
2929
@@ -42,7 +42,7 @@ type Edge struct {
4242 Path * Key // path from parent to child
4343}
4444
45- func (e * Edge ) Hash (hash hashFunc ) * felt.Felt {
45+ func (e * Edge ) Hash (hash HashFunc ) * felt.Felt {
4646 length := make ([]byte , len (e .Path .bitset ))
4747 length [len (e .Path .bitset )- 1 ] = e .Path .len
4848 pathFelt := e .Path .Felt ()
@@ -54,6 +54,11 @@ func (e *Edge) Len() uint8 {
5454 return e .Path .Len ()
5555}
5656
57+ func (e * Edge ) PathInt () uint64 {
58+ f := e .Path .Felt ()
59+ return f .Uint64 ()
60+ }
61+
5762func (e * Edge ) PrettyPrint () {
5863 fmt .Printf (" Edge:\n " )
5964 fmt .Printf (" Child: %v\n " , e .Child )
@@ -199,7 +204,7 @@ func traverseNodes(currNode ProofNode, path *[]ProofNode, nodeHashes map[felt.Fe
199204// merges paths in the specified order [commonNodes..., leftNodes..., rightNodes...]
200205// ordering of the merged path is not important
201206// since SplitProofPath can discover the left and right paths using the merged path and the rootHash
202- func MergeProofPaths (leftPath , rightPath []ProofNode , hash hashFunc ) ([]ProofNode , * felt.Felt , error ) {
207+ func MergeProofPaths (leftPath , rightPath []ProofNode , hash HashFunc ) ([]ProofNode , * felt.Felt , error ) {
203208 merged := []ProofNode {}
204209 minLen := min (len (leftPath ), len (rightPath ))
205210
@@ -236,7 +241,7 @@ func MergeProofPaths(leftPath, rightPath []ProofNode, hash hashFunc) ([]ProofNod
236241// SplitProofPath splits the merged proof path into two paths (left and right), which were merged before
237242// it first validates that the merged path is not circular, the split happens at most once and rootHash exists
238243// then calls traverseNodes to split the path to left and right paths
239- func SplitProofPath (mergedPath []ProofNode , rootHash * felt.Felt , hash hashFunc ) ([]ProofNode , []ProofNode , error ) {
244+ func SplitProofPath (mergedPath []ProofNode , rootHash * felt.Felt , hash HashFunc ) ([]ProofNode , []ProofNode , error ) {
240245 commonPath := []ProofNode {}
241246 leftPath := []ProofNode {}
242247 rightPath := []ProofNode {}
@@ -316,7 +321,7 @@ func GetProof(key *Key, tri *Trie) ([]ProofNode, error) {
316321
317322// verifyProof checks if `leafPath` leads from `root` to `leafHash` along the `proofNodes`
318323// https://github.com/eqlabs/pathfinder/blob/main/crates/merkle-tree/src/tree.rs#L2006
319- func VerifyProof (root * felt.Felt , key * Key , value * felt.Felt , proofs []ProofNode , hash hashFunc ) bool {
324+ func VerifyProof (root * felt.Felt , key * Key , value * felt.Felt , proofs []ProofNode , hash HashFunc ) bool {
320325 expectedHash := root
321326 remainingPath := NewKey (key .len , key .bitset [:])
322327 for i , proofNode := range proofs {
@@ -345,7 +350,7 @@ func VerifyProof(root *felt.Felt, key *Key, value *felt.Felt, proofs []ProofNode
345350 return true
346351 }
347352
348- if ! proofNode .Path .Equal (subKey ) {
353+ if ! proofNode .Path .Equal (subKey ) && ! subKey . Equal ( & Key {}) {
349354 return false
350355 }
351356 expectedHash = proofNode .Child
@@ -363,7 +368,7 @@ func VerifyProof(root *felt.Felt, key *Key, value *felt.Felt, proofs []ProofNode
363368// and therefore it's hash won't match the expected root.
364369// ref: https://github.com/ethereum/go-ethereum/blob/v1.14.3/trie/proof.go#L484
365370func VerifyRangeProof (root * felt.Felt , keys , values []* felt.Felt , proofKeys [2 ]* Key , proofValues [2 ]* felt.Felt ,
366- proofs [2 ][]ProofNode , hash hashFunc ,
371+ proofs [2 ][]ProofNode , hash HashFunc ,
367372) (bool , error ) {
368373 // Step 0: checks
369374 if len (keys ) != len (values ) {
@@ -440,7 +445,7 @@ func ensureMonotonicIncreasing(proofKeys [2]*Key, keys []*felt.Felt) error {
440445}
441446
442447// compressNode determines if the node needs compressed, and if so, the len needed to arrive at the next key
443- func compressNode (idx int , proofNodes []ProofNode , hashF hashFunc ) (int , uint8 , error ) {
448+ func compressNode (idx int , proofNodes []ProofNode , hashF HashFunc ) (int , uint8 , error ) {
444449 parent := proofNodes [idx ]
445450
446451 if idx == len (proofNodes )- 1 {
@@ -474,7 +479,7 @@ func compressNode(idx int, proofNodes []ProofNode, hashF hashFunc) (int, uint8,
474479}
475480
476481func assignChild (i , compressedParent int , parentNode * Node ,
477- nilKey , leafKey , parentKey * Key , proofNodes []ProofNode , hashF hashFunc ,
482+ nilKey , leafKey , parentKey * Key , proofNodes []ProofNode , hashF HashFunc ,
478483) (* Key , error ) {
479484 childInd := i + compressedParent + 1
480485 childKey , err := getChildKey (childInd , parentKey , leafKey , nilKey , proofNodes , hashF )
@@ -494,7 +499,7 @@ func assignChild(i, compressedParent int, parentNode *Node,
494499// ProofToPath returns a set of storage nodes from the root to the end of the proof path.
495500// The storage nodes will have the hashes of the children, but only the key of the child
496501// along the path outlined by the proof.
497- func ProofToPath (proofNodes []ProofNode , leafKey * Key , hashF hashFunc ) ([]StorageNode , error ) {
502+ func ProofToPath (proofNodes []ProofNode , leafKey * Key , hashF HashFunc ) ([]StorageNode , error ) {
498503 pathNodes := []StorageNode {}
499504
500505 // Child keys that can't be derived are set to nilKey, so that we can store the node
@@ -552,7 +557,7 @@ func ProofToPath(proofNodes []ProofNode, leafKey *Key, hashF hashFunc) ([]Storag
552557 return pathNodes , nil
553558}
554559
555- func skipNode (pNode ProofNode , pathNodes []StorageNode , hashF hashFunc ) bool {
560+ func skipNode (pNode ProofNode , pathNodes []StorageNode , hashF HashFunc ) bool {
556561 lastNode := pathNodes [len (pathNodes )- 1 ].node
557562 noLeftMatch , noRightMatch := false , false
558563 if lastNode .LeftHash != nil && ! pNode .Hash (hashF ).Equal (lastNode .LeftHash ) {
@@ -607,7 +612,7 @@ func getParentKey(idx int, compressedParentOffset uint8, leafKey *Key,
607612 return crntKey , err
608613}
609614
610- func getChildKey (childIdx int , crntKey , leafKey , nilKey * Key , proofNodes []ProofNode , hashF hashFunc ) (* Key , error ) {
615+ func getChildKey (childIdx int , crntKey , leafKey , nilKey * Key , proofNodes []ProofNode , hashF HashFunc ) (* Key , error ) {
611616 if childIdx > len (proofNodes )- 1 {
612617 return nilKey , nil
613618 }
0 commit comments