Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap/merge range and proof #1913

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5cd826f
updating verify proof range to handle empty proof keys
Jun 7, 2024
3ecb395
test non set proof key - wip
Jun 7, 2024
d2fe491
wip - proof to Path doesn't work
Jun 7, 2024
2cd3157
store the hashes of children in ProofToPath
Jun 8, 2024
3603e28
ProoftoPath update to handle unset proof key
Jun 8, 2024
d8f5811
test - wip
Jun 8, 2024
40a3d04
test - wip
Jun 9, 2024
fb6c899
test passes! :D
Jun 10, 2024
07e99f5
lint
Jun 10, 2024
c0b933a
tidy
Jun 10, 2024
529aef2
fixing tests that broke wip
Jun 10, 2024
ca360e9
build4keyTrie passes again!
Jun 11, 2024
fdf6af2
fixed more tests
Jun 11, 2024
9f9f2fe
fix test wip
Jun 11, 2024
bad7267
fix more tests
Jun 11, 2024
92a98df
fix test -wip
Jun 11, 2024
727801b
fix tests wip
Jun 11, 2024
b4ae2b6
wip
Jun 11, 2024
a123730
all tests passgit add .
Jun 12, 2024
d249186
lint
Jun 12, 2024
21f9453
tidy
Jun 12, 2024
2d7c6e8
tidy logic
Jun 12, 2024
46c7b8a
tidy logic
Jun 12, 2024
0bb2edc
tidy logic
Jun 12, 2024
ce20e08
comment: update getLeftRightHash
Jun 12, 2024
ec2f917
update ProofToPath comment
Jun 12, 2024
dd21cc0
bubble up getLeftRightHash err
Jun 12, 2024
571eb6e
Trie iterate
asdacap Jun 14, 2024
b614c2e
Address comment
asdacap Jun 14, 2024
89cf035
Merge branch 'feature/trie-iterate' into snap/merge-range-and-proof
asdacap Jun 19, 2024
20e2aa0
Snap support
asdacap Jun 20, 2024
faa0884
Finished is needed internally
asdacap Jun 20, 2024
59440ac
Missed a printf
asdacap Jun 20, 2024
35b46d0
Format
asdacap Jun 20, 2024
cb26dd7
Fix lint
asdacap Jun 20, 2024
1454ad5
Update core/trie/key.go
asdacap Jun 25, 2024
d4b4232
Update core/trie/snap_support.go
asdacap Jun 25, 2024
4f4940f
address keys
asdacap Jun 27, 2024
909914d
Fix lint
asdacap Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test - wip
  • Loading branch information
rian committed Jun 12, 2024
commit d8f581121faadb71c0fd7bf643594ec8f274025e
17 changes: 15 additions & 2 deletions core/trie/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ 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)) {
// Can't store nil keys so stop merging
if leftProofPath[i].node.Left == nil || leftProofPath[i].node.Right == nil ||
rightProofPath[i].node.Left == nil || rightProofPath[i].node.Right == nil {
break
}
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 @@ -463,14 +468,22 @@ func BuildTrie(leftProofPath, rightProofPath []StorageNode, keys, values []*felt
}

for _, sNode := range leftProofPath {
// Can't store nil keys (reached end of line for proof)
if sNode.node.Left == nil || sNode.node.Right == nil {
break
}
_, err := tempTrie.PutInner(sNode.key, sNode.node)
if err != nil {
return nil, err
}
}

for _, sNode := range rightProofPath {
_, err := tempTrie.PutInner(sNode.key, sNode.node) // Todo: incorrectly sets the proof key
// Can't store nil keys (reached end of line for proof)
if sNode.node.Left == nil || sNode.node.Right == nil {
break
}
_, err := tempTrie.PutInner(sNode.key, sNode.node)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion core/trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,17 @@ func TestVerifyRangeProof(t *testing.T) {
rightProof, err := trie.GetProof(proofKeys[1], tri) // Looks correct in terms of binary and edges
require.NoError(t, err)

// Todo: remove, just included for inspection/testing
leftProofPath, err := trie.ProofToPath(leftProof, proofKeys[0], proofValues[0], crypto.Pedersen) // correct
require.NoError(t, err)
rightProofPath, err := trie.ProofToPath(rightProof, proofKeys[1], proofValues[1], crypto.Pedersen) // gives the correct structure
require.NoError(t, err)
fmt.Println(leftProofPath, rightProofPath)

proofs := [2][]trie.ProofNode{leftProof, rightProof}
rootCommitment, err := tri.Root()
require.NoError(t, err)
verif, err := trie.VerifyRangeProof(rootCommitment, keys, values, proofKeys, proofValues, proofs, crypto.Pedersen)
verif, err := trie.VerifyRangeProof(rootCommitment, keys, values, proofKeys, proofValues, proofs, crypto.Pedersen) // todo: panics
require.NoError(t, err)
require.True(t, verif)
})
Expand Down
2 changes: 0 additions & 2 deletions core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ func (t *Trie) insertOrUpdateValue(nodeKey *Key, node *Node, nodes []StorageNode
newParent.Value = t.hash(node.LeftHash, rightChild.Hash(&rightPath, t.hash))
} else if node.RightHash != nil {
newParent.Value = t.hash(leftChild.Hash(&leftPath, t.hash), node.RightHash)
} else {
return errors.New("proof node has neither right/left child hash")
}
} else {
newParent.Value = t.hash(leftChild.Hash(&leftPath, t.hash), rightChild.Hash(&rightPath, t.hash))
Expand Down