Skip to content

There is no way to prove contract code over rsk/64, and no codeHash in the account record to check it against #393

Open

Description

@SDL-A1

crates/networking/src/protocol/rsk.rs:171-178, crates/trie/src/account.rs:13,
crates/rpc/src/proof.rs:296-302.

TrieProofRequest carries address and storage_keys. There is no way to
ask for an account's code, and the p2p server never touches code_key.

On Ethereum this would be a convenience: a light client fetches code by hash
and checks it against the codeHash field of the authenticated account.
The RSK account record is

pub struct AccountState {
    pub nonce: U256,
    pub balance: U256,
    pub state_flags: u32,
}

There is no code hash in it. So hashing the bytes and comparing is not
available either, and the only way to authenticate code on this chain is a
proof of the code key itself -- which the proof message cannot request.

proof.rs says as much where it builds the light-path response:

Two fields a light client cannot honestly fill. codeHash would need the
code itself, and storageHash the storage-prefix node; neither was asked
for, and inventing a plausible constant for either would be worse than
saying nothing.

Why it is worth an issue

Three things are blocked, and the third is the one that matters most:

  1. eth_getCode cannot be served verifiably by an SPV node.
  2. eth_getProof returns an EIP-1186-shaped response with codeHash and
    storageHash absent, so a caller expecting that shape gets a partial one.
  3. A local verified eth_call is impossible, because an EVM needs code.

(3) is not hypothetical. A wallet showing ERC-20 balances either knows each
token's storage layout -- which is contract-specific and not generally
discoverable -- or it calls balanceOf and verifies the result. The light
client in NethermindEth/nethermind#14457 does the latter: it runs the EVM
locally and demand-pages proven state into it, one missing item per attempt
(Rpc/VerifiedCall.cs, bounded to 128 attempts and 60 seconds). That is the
only route to a verified token balance that does not require a layout oracle,
and on this chain it is closed at the protocol level.

What would settle it

Add two booleans to TrieProofRequest -- include_code and
include_storage_root -- and the matching code_proof and
storage_root_proof paths to TrieProofResponse. Code lives at
code_key(addr) and the storage root is the node at
storage_prefix_key(addr); both are ordinary keys in the same trie, so
nodes_to_divergence proves them and verify_path checks them with no new
logic. eth_getProof could then fill both fields honestly.

Bound the code case deliberately: the proof carries the code as its leaf
value, so a response grows by the contract's size. The server already refuses
requests asking for too many slots; code should get an equivalent stated
limit rather than inheriting none.

The alternative worth deciding on purpose

Generalising the message to carry a list of raw unitrie keys subsumes this and
anything later, at the cost of the typed shape that mirrors EIP-1186 and of
making server-side bounds semantic rather than structural. Both options are
defensible; drifting into one by default is not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions