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

VerifyProofs #1873

Closed
wants to merge 58 commits into from
Closed

VerifyProofs #1873

wants to merge 58 commits into from

Conversation

rianhughes
Copy link
Contributor

@rianhughes rianhughes commented May 21, 2024

The PR implements VerifyRangeProof. It accounts for the cases where either 0, 1 or both boundary proofs are supplied. It does require the proof keys to be set.

Note: It does not account for the case where the proof keys are not set. I have opened a new PR that accounts for this case #1901

@rianhughes rianhughes requested review from kirugan and asdacap May 21, 2024 07:10
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 74.68354% with 60 lines in your changes missing coverage. Please review.

Project coverage is 75.29%. Comparing base (52a8ea9) to head (d90633e).

Files Patch % Lines
core/trie/proof.go 71.08% 27 Missing and 21 partials ⚠️
core/trie/trie.go 83.09% 7 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1873      +/-   ##
==========================================
- Coverage   75.36%   75.29%   -0.08%     
==========================================
  Files          97       97              
  Lines        8342     8561     +219     
==========================================
+ Hits         6287     6446     +159     
- Misses       1523     1556      +33     
- Partials      532      559      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
@rianhughes rianhughes force-pushed the rianhughes/proof-range branch 4 times, most recently from 4ad9b74 to 482e2fd Compare June 3, 2024 08:48
@rianhughes
Copy link
Contributor Author

rianhughes commented Jun 3, 2024

Note: I still need to account for edge cases (eg either single or no proof), but it would be useful to have a set of eyes on this now
Update: these edge cases have been added

// If the trie is constructed incorrectly then the root will have an incorrect key(len,path), and value,
// and therefore it's hash will be incorrect.
// ref: https://github.com/ethereum/go-ethereum/blob/v1.14.3/trie/proof.go#L484
func VerifyRangeProof(root *felt.Felt, keys, values []*felt.Felt, proofKeys, proofValues [2]*felt.Felt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, proof is 1 array, not 2. It got deduplicated into one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single proof is an array, but we need two proofs, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the easiest way to generate the proof is with the left (start query actually, probably will come back later) and right key separately. Then it is combined into one set. I'm guessing this is done because a lot of the time some of the top nodes are going to be duplicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Geth seems to store proofs nodes in a key-value store, so I guess starkware are thinking about dong something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind if I open a separate issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
// Set the children of the current node
// The child may need compressed. If so, point to its compressed form.
childIdx := i + squishedParent + 1
if i+2+squishedParent < len(proofNodes)-1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-else here is pure magic - I cannot understand why we're looking at 3 different cases:

  • i+2+squishedParent < len(proofNodes)-1
  • i+1+offset == len(proofNodes)-1
  • otherwise

also I feel me might want to refactor the crntNode construction into a functions which would do the leafKey.Test(...) because a lot of code is duplicated or similar and it's hard to follow what happens

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments and refactored a bit. Let me know if it's still unclear!

Copy link
Contributor Author

@rianhughes rianhughes Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an update: this logic is / will be simplified in this PR. It should be a lot clearer there, but I can push those changes here if you'd like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to push it here, we can review the changes in PR #1901

@rianhughes rianhughes force-pushed the rianhughes/proof-range branch from eb092d4 to 8de028b Compare June 7, 2024 08:03
@rianhughes rianhughes requested review from pnowosie and asdacap June 7, 2024 13:08
@rianhughes
Copy link
Contributor Author

This PR is / can be replaced by this #1901

@rianhughes
Copy link
Contributor Author

closing for #1901

@rianhughes rianhughes closed this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants