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

Add State Override Support for eth_call #2122

Closed
Jouzo opened this issue Jun 26, 2023 · 1 comment · Fixed by #2623
Closed

Add State Override Support for eth_call #2122

Jouzo opened this issue Jun 26, 2023 · 1 comment · Fixed by #2623
Labels
evm p3 Low priority rpc up-for-grab PRs are welcome // up for grab for anyone to work on

Comments

@Jouzo
Copy link
Collaborator

Jouzo commented Jun 26, 2023

Summary

Extend eth_call RPC to include a state_overrides parameter for more flexible contract testing.

Rationale

This allows end users to specify a temporary state against which testing their contract deployment or interaction. This override should be temporary and should not affect the actual state of the blockchain. This ensures that developers can run these simulations without unintentionally altering the state of the blockchain.
This helps developer with smart contract debugging and analysis.
It can potentially reduce the amount of code deployed on-chain. Code that simply returns internal state or does pre-defined validations can be kept off chain and fed to the node on-demand.

Design

Additional state override struct :

struct StateOverride {
	pub balance: Option<U256>, 
	pub nonce: Option<U256>,
	pub code: Option<Bytes>, // code of the contract, if any
	pub state: Option<BTreeMap<H256, H256>>, // state of the contract
	pub state_diff: Option<BTreeMap<H256, H256>>, // the difference in state from the original
}
BTreeMap<H160, StateOverride>

RPC

eth_call example :

eth_call { from: "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3", to: <contract_address>, input: <data> } "latest"
{
  "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3": {
    "balance": "0xde0b6b3a7640000"
  }
}

The balance of the from address is set to "0xde0b6b3a7640000" for the context of this call


Ref : https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-eth

@Jouzo Jouzo added up-for-grab PRs are welcome // up for grab for anyone to work on rpc p3 Low priority evm labels Jun 27, 2023
@Jouzo
Copy link
Collaborator Author

Jouzo commented Oct 25, 2023

Can add an Optional to EVMBackend from_root method once
#2611 is in. Should be a pretty straightforward impl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evm p3 Low priority rpc up-for-grab PRs are welcome // up for grab for anyone to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant