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
lint
  • Loading branch information
rian committed Jun 12, 2024
commit 07e99f5c394704e00066adf2243d3585e1873a60
38 changes: 18 additions & 20 deletions core/trie/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,38 @@ func (n *Node) WriteTo(buf *bytes.Buffer) (int64, error) {
}

if n.Left != nil {
wrote, err := n.Left.WriteTo(buf)
wrote, errInner := n.Left.WriteTo(buf)
totalBytes += wrote
if err != nil {
return totalBytes, err
return totalBytes, errInner
}
wrote, err = n.Right.WriteTo(buf) // n.Right is non-nil by design
wrote, errInner = n.Right.WriteTo(buf) // n.Right is non-nil by design
totalBytes += wrote
if err != nil {
return totalBytes, err
return totalBytes, errInner
}
}

if n.LeftHash == nil && n.RightHash == nil {
return totalBytes, nil
}
if (n.LeftHash != nil && n.RightHash == nil) || (n.LeftHash == nil && n.RightHash != nil) {
} else if (n.LeftHash != nil && n.RightHash == nil) || (n.LeftHash == nil && n.RightHash != nil) {
return totalBytes, errors.New("cannot store only one lefthash or righthash")
}
if n.LeftHash != nil {
leftHashB := n.LeftHash.Bytes()
wrote, err := buf.Write(leftHashB[:])
totalBytes += int64(wrote)
if err != nil {
return totalBytes, err
}

leftHashB := n.LeftHash.Bytes()
wrote, err = buf.Write(leftHashB[:])
totalBytes += int64(wrote)
if err != nil {
return totalBytes, err
}
if n.Right != nil {
rightHashB := n.RightHash.Bytes()
wrote, err := buf.Write(rightHashB[:])
totalBytes += int64(wrote)
if err != nil {
return totalBytes, err
}

rightHashB := n.RightHash.Bytes()
wrote, err = buf.Write(rightHashB[:])
totalBytes += int64(wrote)
if err != nil {
return totalBytes, err
}

return totalBytes, nil
}

Expand Down
5 changes: 2 additions & 3 deletions core/trie/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ func shouldSquish(idx int, proofNodes []ProofNode, hashF hashFunc) (int, uint8,
} else {
panic("can't determine the child hash from the parent and child") // Todo: pass error up
}

}

if parent.Binary != nil && child.Binary != nil {
Expand Down Expand Up @@ -400,7 +399,7 @@ func ProofToPath(proofNodes []ProofNode, leafKey *Key, leafValue *felt.Felt, has
crntNode.RightHash = rightHash

// If current key is a leaf then don't set the children
if crntKey.len == 251 {
if crntKey.len == 251 { //nolint:gomnd
break
}

Expand Down Expand Up @@ -459,7 +458,7 @@ func addLeafNode(proofNodes []ProofNode, pathNodes []StorageNode, leafKey *Key)
}

// BuildTrie builds a trie using the proof paths (including inner nodes), and then sets all the keys-values (leaves)
func BuildTrie(leftProofPath, rightProofPath []StorageNode, keys, values []*felt.Felt) (*Trie, error) {
func BuildTrie(leftProofPath, rightProofPath []StorageNode, keys, values []*felt.Felt) (*Trie, error) { //nolint:gocyclo
tempTrie, err := NewTriePedersen(newMemStorage(), 251) //nolint:gomnd
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ func (t *Trie) updateChildTriesConcurrently(root *Node, leftIsProof, rightIsProo
if !leftIsProof {
leftChild, lErr = t.updateValueIfDirty(root.Left)
}

}()
if !rightIsProof {
rightChild, rErr = t.updateValueIfDirty(root.Right)
Expand Down Expand Up @@ -622,7 +621,7 @@ func (t *Trie) Root() (*felt.Felt, error) {
if err := t.storage.DeleteRootKey(); err != nil {
return nil, err
}
} else if err := t.storage.PutRootKey(t.rootKey); err != nil { //Todo: t.rootKey is set here but not found below???
} else if err := t.storage.PutRootKey(t.rootKey); err != nil { // Todo: t.rootKey is set here but not found below???
return nil, err
}
t.rootKeyIsDirty = false
Expand Down