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

Support eth_getProof JSON RPC method #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Support eth_getProof JSON RPC method #251

wants to merge 2 commits into from

Conversation

fedejinich
Copy link
Contributor

@fedejinich fedejinich commented Jun 30, 2021

Introducing a new JSON RPC method to retrieve merkle proofs from the JSON RPC layer. Useful for state verifications

@fedejinich
Copy link
Contributor Author

fedejinich commented Jun 30, 2021

@SergioDemianLerner It'd be interesting to know your thoughts about this RSKIP, specially the verifications for non existing accounts (or storage keys). To me it seems more clear to return empty lists for any of those scenarios

In case an address or storage-value does not exist, the proof needs to provide enough data to verify this fact. This means the client needs to follow the path from the root node and deliver until the last matching node. If the last matching node is a branch, the proof value in the node must be an empty one. In case of leaf-type, it must be pointing to a different relative-path in order to proof that the requested path does not exist.

@fedejinich
Copy link
Contributor Author

fedejinich commented Jun 30, 2021

also I still need to add some tests cases and code to the spec

IPs/RSKIP251.md Outdated

RSK implements a Unitrie data structure to store all the relevant blockchain data, such as account states and storage values, this particular data structure enables an easy verification of each stored value, just by getting a merkle proof. Currently these proofs are only useful for blockchain nodes, but in order to allow verification of accounts outside the client, we need an additional function delivering us the required proof.

Combined with a stateRoot (from the blockheader) it enables offline verification of any account or storage-value.
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. This sentence should be part of the above paragraph.. the "it" in "it enables" refers to the function mentioned above
  2. ... enables "offline verification" .. what does "offline" mean?
  3. Even though it is mentioned in title (and motivation), it is good to explicitly say this is a RPC method in the abstract

IPs/RSKIP251.md Outdated

## Motivation

Offering these function through the RPC-Interface would enable applications to store and send proofs to devices which are not directly connected to the p2p-network and still are able to verify the data. This could be used for mobile applications, which are currently only using a remote client.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo these function -> this function
.. there are some other minor typos, we can clean them up later :)

IPs/RSKIP251.md Outdated

Offering these function through the RPC-Interface would enable applications to store and send proofs to devices which are not directly connected to the p2p-network and still are able to verify the data. This could be used for mobile applications, which are currently only using a remote client.

Also it might be useful for L2 solutions.
Copy link
Contributor

Choose a reason for hiding this comment

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

move to above paragraph

- balance (QUANTITY)
- codeHash (UNFORMATTED): SHA3 of the code associated to the specifica account (for EOA just retrieve SHA3(EMPTY_BYTE_ARRAY))
- nonce (QUANTITY)
- storageHash (UNFORMATTED): hash of the code of the account. For a EOA it will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" == SHA3(EMPTY_BYTE_ARRAY)
Copy link
Contributor

Choose a reason for hiding this comment

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

hash of "code" -> hash of "value" in storage node/ cell (for the given the storage key)

- codeHash (UNFORMATTED): SHA3 of the code associated to the specifica account (for EOA just retrieve SHA3(EMPTY_BYTE_ARRAY))
- nonce (QUANTITY)
- storageHash (UNFORMATTED): hash of the code of the account. For a EOA it will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" == SHA3(EMPTY_BYTE_ARRAY)
- accountProof (UNFORMATED[]): Array of rlp-serialized MerkleTree-Nodes, starting with the stateRoot-Node, following the path of the SHA3(address) as key.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor typo unformated -> unformatted

- Storage-entry:
- Key (UNFORMATTED): Requested storage key
- Value (QUANTITY): Value contained for that key
- Proof (UNFORMATED[]): Array of rlp-serialized MerkleTree-Nodes, starting with the storageHash-Node, following the path of the SHA3(key) as path.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor typo unformated -> unformatted

- Value (QUANTITY): Value contained for that key
- Proof (UNFORMATED[]): Array of rlp-serialized MerkleTree-Nodes, starting with the storageHash-Node, following the path of the SHA3(key) as path.

Each unitrie node should be serialized as described in the [RSKIP107](https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP107.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

how/why is the serialization relevant for the RPC method?


Each unitrie node should be serialized as described in the [RSKIP107](https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP107.md)

### Address or storage non existent values
Copy link
Contributor

Choose a reason for hiding this comment

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

please change the order, start with Non existent .. e.g. Non existent addresses or storage values


### Address or storage non existent values

If a non-existent address or key from storage is requested, we’ll need to provide enough information to verify that ausence from the outside world. For example, a non existing key will lead to a different node.
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. ausence -> absence?
  2. a non existent key will lead to different node .. I don't follow what different trie node means

Copy link
Collaborator

Choose a reason for hiding this comment

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

unclear meaning of this paragraph.

Do you want to receive a proof of non-membership ?


Note that this is not the same as requesting with wrong parameters, if those params are invalid, we just need to respond as a failed request.

## References
Copy link
Contributor

Choose a reason for hiding this comment

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

These references numbers should be marked in the text where they are cited. For example, it would be nice to cite [1] in the abstract when talking about Merkle proofs for state data

@smishraIOV
Copy link
Contributor

Hey Fede, we can approve the PR, but we will merge it only after Sergio has some time to review it, since you marked him specifically :)

The method eth_getProof() is added to the RPC interface. The method returns the account and storage-values of the specified account including the Merkle-proof.

Params
- address (UNFORMATTED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

which is the name of the field?


Params
- address (UNFORMATTED)
- storage keys that we want to prove (if needed) (UNFORMATTED[])
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here. This field should have a name, right ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What is address specified but starageKeys is omitted ? Are both optional ?

- nonce (QUANTITY)
- storageHash (UNFORMATTED): hash of the code of the account. For a EOA it will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" == SHA3(EMPTY_BYTE_ARRAY)
- accountProof (UNFORMATED[]): Array of rlp-serialized MerkleTree-Nodes, starting with the stateRoot-Node, following the path of the SHA3(address) as key.
- storageProof: Array of storage-entries as requested.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this proof given for the account or for the storage keys given as arguments? It's unclear


### Address or storage non existent values

If a non-existent address or key from storage is requested, we’ll need to provide enough information to verify that ausence from the outside world. For example, a non existing key will lead to a different node.
Copy link
Collaborator

Choose a reason for hiding this comment

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

unclear meaning of this paragraph.

Do you want to receive a proof of non-membership ?

@smishraIOV
Copy link
Contributor

@fedejinich this PR has stagnated for a long time. When you get the chance, please update it to address some of the major comments, so we can merge the PR. Further discussions can then happen on the RSK research forum.

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