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
Finished is needed internally
  • Loading branch information
asdacap committed Jun 20, 2024
commit faa0884c3eb98a7a6b8e90cfb413f3d3175384b4
10 changes: 5 additions & 5 deletions core/trie/snap_support.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package trie

import (
"fmt"

Check failure on line 4 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"github.com/NethermindEth/juno/core/felt"
)

func (t *Trie) IterateAndGenerateProof(startValue *felt.Felt, consumer func(key, value *felt.Felt) (bool, error)) ([]ProofNode, error) {
func (t *Trie) IterateAndGenerateProof(startValue *felt.Felt, consumer func(key, value *felt.Felt) (bool, error)) ([]ProofNode, bool, error) {

Check failure on line 8 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

line is 142 characters (lll)
var lastKey *felt.Felt

finished, err := t.Iterate(startValue, func(key, value *felt.Felt) (bool, error) {
Expand All @@ -14,7 +14,7 @@
return consumer(key, value)
})
if err != nil {
return nil, err
return nil, false, err

Check warning on line 17 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L17

Added line #L17 was not covered by tests
}

proofset := map[felt.Felt]ProofNode{}
Expand All @@ -27,21 +27,21 @@
// actually check that the server did not skip leafs.
leftProof, err := GetProof(&startKey, t)
if err != nil {
return nil, err
return nil, false, err

Check warning on line 30 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L30

Added line #L30 was not covered by tests
}
for _, proof := range leftProof {
// Well.. using the trie hash here is kinda slow... but I just need it to work right now.
proofset[*proof.Hash(t.hash)] = proof
}

}

Check failure on line 37 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)

if !finished && lastKey != nil {
feltBts := lastKey.Bytes()
lastKey := NewKey(t.height, feltBts[:])
rightProof, err := GetProof(&lastKey, t)
if err != nil {
return nil, err
return nil, false, err

Check warning on line 44 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L44

Added line #L44 was not covered by tests
}

for _, proof := range rightProof {
Expand All @@ -54,10 +54,10 @@
proofs = append(proofs, node)
}

return proofs, nil
return proofs, finished, nil
}

func VerifyRange(root, startKey *felt.Felt, keys, values []*felt.Felt, proofs []ProofNode, hash hashFunc) (hasMore bool, valid bool, err error) {

Check failure on line 60 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

paramTypeCombine: func(root, startKey *felt.Felt, keys, values []*felt.Felt, proofs []ProofNode, hash hashFunc) (hasMore bool, valid bool, err error) could be replaced with func(root, startKey *felt.Felt, keys, values []*felt.Felt, proofs []ProofNode, hash hashFunc) (hasMore, valid bool, err error) (gocritic)
proofMap := map[felt.Felt]ProofNode{}
for _, proof := range proofs {
proofHash := proof.Hash(hash)
Expand All @@ -68,21 +68,21 @@
// Special case where the whole trie is sent in one go.
// We just need to completely reconstruct the trie.

tempTrie, err := newTrie(newMemStorage(), 251, hash) //nolint:gomnd

Check failure on line 71 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 60 (govet)
if err != nil {
return false, false, err

Check warning on line 73 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L73

Added line #L73 was not covered by tests
}

for i, key := range keys {
_, err := tempTrie.Put(key, values[i])
if err != nil {
return false, false, err

Check warning on line 79 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L79

Added line #L79 was not covered by tests
}
}

recalculatedRoot, err := tempTrie.Root()
if err != nil {
return false, false, err

Check warning on line 85 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L85

Added line #L85 was not covered by tests
}

if !root.Equal(recalculatedRoot) {
Expand All @@ -101,11 +101,11 @@
proofKeys := map[felt.Felt]Key{}
err = buildKeys(NewKey(0, []byte{}), root, proofMap, proofKeys, 0)
if err != nil {
return false, false, err

Check warning on line 104 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L104

Added line #L104 was not covered by tests
}

// No idea how this work
/*

Check failure on line 108 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
proofValuesArray := []*felt.Felt{}
proofKeysArray := []*Key{}
for f, key := range proofKeys {
Expand All @@ -122,7 +122,7 @@
}

feltBytes := hasMoreKeyCheck.Bytes()
asdacap marked this conversation as resolved.
Show resolved Hide resolved
hasMoreKeyCheckKey := NewKey(251, feltBytes[:])

Check failure on line 125 in core/trie/snap_support.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 251, in <argument> detected (gomnd)

// does this actually work on all case?
hasMore = false
Expand All @@ -148,7 +148,7 @@
ch := proofNode.Edge.Child
err := buildKeys(chKey, ch, proofMap, keys, depth+1)
if err != nil {
return err

Check warning on line 151 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L151

Added line #L151 was not covered by tests
}
} else {
binary := proofNode.Binary
Expand All @@ -157,14 +157,14 @@
ch := binary.LeftHash
err := buildKeys(chKey, ch, proofMap, keys, depth+1)
if err != nil {
return err

Check warning on line 160 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L160

Added line #L160 was not covered by tests
}

chKey = currentKey.AppendBit(true)
ch = binary.RightHash
err = buildKeys(chKey, ch, proofMap, keys, depth+1)
if err != nil {
return err

Check warning on line 167 in core/trie/snap_support.go

View check run for this annotation

Codecov / codecov/patch

core/trie/snap_support.go#L167

Added line #L167 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/trie/snap_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestRangeAndVerify(t *testing.T) {
var keys []*felt.Felt
var values []*felt.Felt

proofs, err := testTrie.IterateAndGenerateProof(startQuery, func(key, value *felt.Felt) (bool, error) {
proofs, _, err := testTrie.IterateAndGenerateProof(startQuery, func(key, value *felt.Felt) (bool, error) {
keys = append(keys, key)
values = append(values, value)
if scenario.maxNode > 0 && len(keys) >= scenario.maxNode {
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestRangeAndVerifyReject(t *testing.T) {
var keys []*felt.Felt
var values []*felt.Felt

proofs, err := testTrie.IterateAndGenerateProof(startQuery, func(key, value *felt.Felt) (bool, error) {
proofs, _, err := testTrie.IterateAndGenerateProof(startQuery, func(key, value *felt.Felt) (bool, error) {
keys = append(keys, key)
values = append(values, value)
if scenario.maxNode > 0 && len(keys) >= scenario.maxNode {
Expand Down
Loading