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

Starknet's getStorageProof rpc method #2194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pnowosie
Copy link
Contributor

@pnowosie pnowosie commented Oct 3, 2024

Fixes #2180
Tests are based on proof-refactor PR

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 75.43860% with 70 lines in your changes missing coverage. Please review.

Project coverage is 74.53%. Comparing base (4ff174d) to head (d4b65b1).

Files with missing lines Patch % Lines
rpc/storage.go 87.76% 16 Missing and 7 partials ⚠️
core/trie/proofset.go 0.00% 22 Missing ⚠️
core/state.go 34.37% 15 Missing and 6 partials ⚠️
blockchain/blockchain.go 62.50% 2 Missing and 1 partial ⚠️
core/trie/node.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2194      +/-   ##
==========================================
+ Coverage   74.38%   74.53%   +0.15%     
==========================================
  Files         109      111       +2     
  Lines       11493    11747     +254     
==========================================
+ Hits         8549     8756     +207     
- Misses       2278     2318      +40     
- Partials      666      673       +7     

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

@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch from 301250f to d383531 Compare October 3, 2024 15:11
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch from 1ef09de to a33464e Compare October 10, 2024 07:58
@pnowosie pnowosie marked this pull request as ready for review October 10, 2024 07:59
core/state.go Show resolved Hide resolved
rpc/storage_test.go Outdated Show resolved Hide resolved
rpc/storage_test.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
rpc/handlers.go Outdated Show resolved Hide resolved
blockchain/pending.go Outdated Show resolved Hide resolved
rpc/handlers.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
rpc/storage.go Outdated Show resolved Hide resolved
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 2 times, most recently from b292454 to 1e50ea2 Compare October 11, 2024 07:42
@pnowosie pnowosie requested a review from rianhughes October 11, 2024 11:03
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 2 times, most recently from f9089bc to f3ded4a Compare October 16, 2024 12:09
starknet/.gitignore Outdated Show resolved Hide resolved
@rianhughes rianhughes self-requested a review October 17, 2024 06:47
rpc/storage_test.go Outdated Show resolved Hide resolved
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch from 45a589f to 7252e10 Compare November 1, 2024 08:47
@pnowosie
Copy link
Contributor Author

pnowosie commented Nov 1, 2024

Differences / Issues spotted comparing with PF

1. Params are not optional (why?)

Request

{
  "jsonrpc": "2.0",
  "method": "starknet_getStorageProof",
  "params": [
    "latest",
    ["0x1adadae7ce7ed3f5c39f275ef4758562e540f27ab0184b24e2b13861988751e"]
  ],
  "id": 1
}

Response
"message": "Invalid Params",

2. Response does not filter out duplicate nodes in hash HashToNode mapping

Request

{
  "jsonrpc": "2.0",
  "method": "starknet_getStorageProof",
  "params": [
    "latest",
    ["0x1adadae7ce7ed3f5c39f275ef4758562e540f27ab0184b24e2b13861988751e", 
     "0x1adadae7ce7ed3f5c39f275ef4758562e540f27ab0184b24e2b13861988751e"],
    [],
    []
  ],
  "id": 1
}

Response

{
  "jsonrpc": "2.0",
  "result": {
    "classes_proof": [
      {
        "node_hash": "0x217d3fbc3bccaca79f86feb5e9dbbfa531ab481503594df9ca426245a65a12f",
        "node": { ... }
      },
// ...
      {
        "node_hash": "0x1c2825874f9b479403ea627428397852d86c67d955be072d68de143a98bb923",
        "node": { ...
          "child": "0x35f5f9b5523cdbd190f2d7a7310aadcfcf0231a9a580786b9cd5db8b512de2"
        }
      },
      {
        "node_hash": "0x217d3fbc3bccaca79f86feb5e9dbbfa531ab481503594df9ca426245a65a12f",
         "node": { ... }
      },
// ...
      {
        "node_hash": "0x1c2825874f9b479403ea627428397852d86c67d955be072d68de143a98bb923",
        "node": { ...
          "child": "0x35f5f9b5523cdbd190f2d7a7310aadcfcf0231a9a580786b9cd5db8b512de2"
        }
      }
    ],
  // ...
  "id": 1
}

Comment on lines 324 to 326
proofHash := proofNode.Hash(hash)
fmt.Println("Proof verification failure", "node", proofHash, "expected", expectedHash)
fmt.Printf("%v\n", proofNode)
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove these debugging lines

@@ -345,7 +348,8 @@ func VerifyProof(root *felt.Felt, key *Key, value *felt.Felt, proofs []ProofNode
return true
}

if !proofNode.Path.Equal(subKey) {
if !proofNode.Path.Equal(subKey) && !subKey.Equal(&Key{}) {
fmt.Println("Proof verification failure", "node", proofNode.Path, "expected", subKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove these debugging lines

core/trie/key.go Outdated
Comment on lines 31 to 67
if n == k.len {
return &Key{}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this check needed?

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 found a bug in proof-verification here in the test:

require.True(t, trie.VerifyProof(root, &kKey, value, proof, tempTrie.HashFunc()))

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, that actually doesn't fix the other test cases. It'll be clearer in my VerifyProof implementation.

@weiihann
Copy link
Contributor

weiihann commented Nov 1, 2024

I discussed this issue with @kirugan and we agreed that we address this once we allow juno to prove historical states

So there are 2 approaches we can take:

  1. Implements TrieReader interface and return HeadTrie in Blockchain Reader interface
  2. Add Trie access methods in StateReader interface

For the 1st approach, we can agree on the architecture such that a Blockchain Reader shouldn't know the underlying State implementation (i.e. Trie). Adding HeadTrie method to Reader indicates we are coupling Trie and Blockchain together, which shouldn't happen. So essentially this is a technical debt.

For the 2nd approach, the architecture makes sense, the issue is that we have an unsupported feature for historical trie access. It's unsure when we will support historical trie access as it's a huge refactor on the state, trie and db modules.

I'd rather go with an unsupported feature and detect it early rather than incur technical debts and make the modules even more coupled and harder to refactor.

@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch from 7252e10 to 5200b6d Compare November 4, 2024 13:55
@pnowosie pnowosie changed the title Starknet's getProof rpc method Starknet's getStorageProof rpc method Nov 4, 2024
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 5 times, most recently from e0e6727 to 59ca331 Compare November 7, 2024 10:58
core/trie/proof.go Outdated Show resolved Hide resolved
core/trie/proof.go Outdated Show resolved Hide resolved
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 2 times, most recently from 72d964e to 82cf7a9 Compare November 12, 2024 08:20
core/trie/proof_test.go Outdated Show resolved Hide resolved
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 3 times, most recently from 3af5c47 to 084e874 Compare November 20, 2024 10:33
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 3 times, most recently from aa5534a to bef9818 Compare December 9, 2024 10:53
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch 3 times, most recently from 1b2ed80 to 5df78c4 Compare December 13, 2024 12:11
@pnowosie pnowosie force-pushed the pnowosie/2180-starknet-getProof-rpc branch from 5df78c4 to d4b65b1 Compare December 13, 2024 14:19
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.

RPC08 - starknet_getStorageProof
5 participants