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 Support for BeaconRoot and Withdrawals as part of eth_simulateV1 API. #31264

Open
rezbera opened this issue Feb 26, 2025 · 3 comments
Open
Assignees

Comments

@rezbera
Copy link

rezbera commented Feb 26, 2025

Rationale

Why should this feature exist?

The eth_simulateV1 API is the most advanced Geth simulation API but is missing core state transitions through BeaconRoot and Withdrawals support. If there is other ways to calculate the StateRoot and ReceiptsRoot without modifying Geth state, let me know!

What are the use-cases?

My usecase demands that I build execution blocks outside of the Geth block builder as I'm trying to hand craft blocks for testing the Engine API responses. For example, I want to hand craft an execution block with an invalid state transition to see how my Consensus Layer deals with the "INVALID_BLOCK" response from NewPayload.

The main blocker for this form of testing is calculating the StateRoot and ReceiptsRoot which requires access to EVM state to generate.
However, every CL will generally have at least a ParentBeaconRoot and often Withdrawals, both of which mutate the state resulting in a change of the StateRoot which is not captured in the eth_simulateV1 API.

Implementation

Do you have ideas regarding the implementation of this feature?

The ParentBeaconRoot handling is trivial to implement, as I've PoC'd this. Not sure about withdrawals but shouldn't be too bad - as long as the default consensus engine is Beacon, we don't need the Headerchain as that's unused.

This can be completely backwards compatible as its just new fields.

Are you willing to implement this feature?

Yea I can have a crack.

@rezbera
Copy link
Author

rezbera commented Feb 26, 2025

It would also be great if we could add support for V, R, S fields of the transaction call, as without these, the transactionHash calculated in the response is incorrect, and so is the from fields.

@s1na
Copy link
Contributor

s1na commented Feb 26, 2025

Hi! this is certainly an interesting use-case. As far as I remember we hadn't added those only because we couldn't think of a use-case for them. So I am open to adding them. Before doing that tho I am wondering if dev mode can be of interest to you. You can use it to build a fully simulated chain. It allows you to add withdrawals and txes. We should add support for the beacon root tho it is now left as the empty hash.

./build/bin/geth --dev console

[...]


> dev.addWithdrawal({ 'index': '0x0', validator: '0x0', address: eth.accounts[0], value: '0x1' })
null
> INFO [02-26|12:35:27.467] Starting work on payload                 id=0x0350e50d99e9c28a
INFO [02-26|12:35:27.468] Updated payload                          id=0x0350e50d99e9c28a number=1 hash=835f32..942303 txs=0 withdrawals=1 gas=0 fees=0 root=6d995c..c9e988 elapsed="469.166µs"
INFO [02-26|12:35:27.468] Stopping work on payload                 id=0x0350e50d99e9c28a reason=delivery
INFO [02-26|12:35:27.469] Imported new potential chain segment     number=1 hash=835f32..942303 blocks=1 txs=0 mgas=0.000 elapsed="680.375µs" mgasps=0.000 snapdiffs=306.00B triediffs=1.45KiB triedirty=0.00B
INFO [02-26|12:35:27.469] Chain head was updated                   number=1 hash=835f32..942303 root=6d995c..c9e988 elapsed="56.375µs"
INFO [02-26|12:35:27.469] Indexed transactions                     blocks=2 txs=0 tail=0 elapsed="118.25µs"
> eth.getBlock(1).withdrawals
[{
    address: "0xa62334ec0d9a35320bb4c0fb3679883d2baf120a",
    amount: "0x0",
    index: "0x0",
    validatorIndex: "0x0"
}]

@rezbera
Copy link
Author

rezbera commented Feb 26, 2025

Thanks @s1na ! Dev Mode does not meet my requirements because the goal is to ultimately submit the Simulated Block to Geth via the Engine API, which requires building the block on actual Geth State to ensure it computes the correct State and Receipt Roots

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

No branches or pull requests

2 participants