Skip to content

Commit

Permalink
wip - proof to Path doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
rian committed Jun 7, 2024
1 parent 3db1bcd commit 0804fab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/trie/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func VerifyRangeProof(root *felt.Felt, keys, values []*felt.Felt, proofKeys [2]*
return false, fmt.Errorf("invalid proof for key %x", proofKeys[i].String())
}

proofPaths[i], err = ProofToPath(proofs[i], proofKeys[i], hash)
proofPaths[i], err = ProofToPath(proofs[i], proofKeys[i], hash) // Todo: incorrect for both paths :(
if err != nil {
return false, err
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func BuildTrie(leftProofPath, rightProofPath []StorageNode, keys, values []*felt
}

// merge proof paths
for i := range min(len(leftProofPath), len(rightProofPath)) {
for i := range min(len(leftProofPath), len(rightProofPath)) { //
if leftProofPath[i].key.Equal(rightProofPath[i].key) {
leftProofPath[i].node.Right = rightProofPath[i].node.Right
rightProofPath[i].node.Left = leftProofPath[i].node.Left
Expand All @@ -447,7 +447,7 @@ func BuildTrie(leftProofPath, rightProofPath []StorageNode, keys, values []*felt
}

for _, sNode := range rightProofPath {
_, err := tempTrie.PutInner(sNode.key, sNode.node)
_, err := tempTrie.PutInner(sNode.key, sNode.node) // Todo: incorrectly sets the proof key
if err != nil {
return nil, err
}
Expand Down
17 changes: 13 additions & 4 deletions core/trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,17 @@ func build4KeyTrie(t *testing.T) *trie.Trie {
// 249 \
// / \ \
// 250 \ \
// / \ \ \
// 0 1 2 4
// / \ /\ /\
// 0 1 2 4

// Juno - should be able to reconstruct this from proofs
// 248
// / \
// 249
// / \
// 250 \
// / \ /\
// 0

// Pathfinder (???)
// 0 Edge
Expand Down Expand Up @@ -850,9 +859,9 @@ func TestVerifyRangeProof(t *testing.T) {
values := []*felt.Felt{new(felt.Felt).SetUint64(5), new(felt.Felt).SetUint64(6)}
proofKeys := [2]*trie.Key{&zeroLeafkey, &threeLeafkey}
proofValues := [2]*felt.Felt{new(felt.Felt).SetUint64(4), nil}
leftProof, err := trie.GetProof(proofKeys[0], tri)
leftProof, err := trie.GetProof(proofKeys[0], tri) // Looks correct in terms of binary and edges
require.NoError(t, err)
rightProof, err := trie.GetProof(proofKeys[1], tri)
rightProof, err := trie.GetProof(proofKeys[1], tri) // Looks correct in terms of binary and edges
require.NoError(t, err)
proofs := [2][]trie.ProofNode{leftProof, rightProof}
rootCommitment, err := tri.Root()
Expand Down

0 comments on commit 0804fab

Please sign in to comment.