diff --git a/core/trie/proof.go b/core/trie/proof.go index 1b57c9d061..2c81c2852c 100644 --- a/core/trie/proof.go +++ b/core/trie/proof.go @@ -190,10 +190,11 @@ func VerifyProof(root *felt.Felt, key *Key, value *felt.Felt, proofs []ProofNode return false } + // Todo: // If we are verifying the key doesn't exist, then we should // update subKey to point in the other direction if value == nil && i == len(proofs)-1 { - return true // todo: hack for non-set proof nodes + return true } if !proofNode.Edge.Path.Equal(subKey) { @@ -294,13 +295,13 @@ func ensureMonotonicIncreasing(proofKeys [2]*Key, keys []*felt.Felt) error { func shouldSquish(idx int, proofNodes []ProofNode, hashF hashFunc) (int, uint8, error) { parent := &proofNodes[idx] if idx == len(proofNodes)-1 { // The node may have children, but we can only derive their hashes here - var hack int + var isEdge int if parent.Edge != nil { - hack = 1 + isEdge = 1 } else if parent.Binary != nil { - hack = 0 + isEdge = 0 } - return hack, parent.Len(), nil + return isEdge, parent.Len(), nil } child := &proofNodes[idx+1] @@ -344,7 +345,7 @@ func assignChild(crntNode *Node, nilKey, childKey *Key, isRight bool) { func ProofToPath(proofNodes []ProofNode, leafKey *Key, hashF hashFunc) ([]StorageNode, error) { pathNodes := []StorageNode{} - // Hack: this allows us to store a right without an existing left node. + // Child keys that can't be derived are set to nilKey, so that we can store the node zeroFeltBytes := new(felt.Felt).Bytes() nilKey := NewKey(0, zeroFeltBytes[:])