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

New overlays feature for doing ad-hoc simulations of existing contracts with modified bytecode #259

Open
wants to merge 9 commits into
base: optimism
Choose a base branch
from

Conversation

crebsy
Copy link

@crebsy crebsy commented Mar 1, 2024

Description

In this PR I'm adding so-called overlays for doing ad-hoc state simulations of contracts which replay the state with a modified bytecode for any given block range post-bedrock. I'm planning to port the same feature into the legacy optimism geth later and delegate the RPC calls to the historical RPC as well like it's being done for other RPC methods already.

The new feature adds two new RPC methods: overlay_callConstructor and overlay_getLogs which can be used to patch a contract with new bytecode and get the modified logs for it.

Tests

I've added a new postman collection for integration testing/refactoring which patches two contracts on OP mainnet which have been created with CREATE and CREATE2. I've also added tests that retrieve all logs with the original bytecode and with the modified one and check the results.

Additional context

Overlays allow you to add your custom logic to already deployed contracts and simulate on top of them. With overlays you can create new view functions, modify existing ones, change field visibility, emit new events and query the historical data of any contract with your modified source code.

Similar commercial products exist in the space and I believe making this feature opensource in op-geth will make it easier for everyone to tinker with it and build new cool things on top of it ✨

Usage
See README

already deployed contracts.

feat: move overlays into separate namespace 'overlay'

feat: finished ConstructorCall() and added func to get the contract creation block

feat: implemented GetLogs

feat: make stateOverride optional

feat: parallel GetLogs

feat: remove old code

fix: move tracer code to the topmost position in the func so it's called before any code is executed

feat: overlays

chore: todo
@crebsy crebsy requested a review from a team as a code owner April 9, 2024 20:02
@crebsy crebsy requested review from trianglesphere and removed request for a team April 9, 2024 20:02
@crebsy
Copy link
Author

crebsy commented Apr 9, 2024

I just rebased this PR to fbf1ff7
anyone wants to test this, pls have a look at my README documenting the new overlay API and the new postman collection. It contains several integration tests for contracts created with CREATE and CREATE2 which are deployed on op-mainnet and can be run against an archive node with postman.

There's also a TODO to add support for patching pre-bedrock contracts if you wanted to use overlays with older contracts which have been originally deployed pre-bedrock. But this could be done later as well imo.

The functionality is very similar to the one from erigon: erigontech/erigon#9438
However, the main difference is performance. Thanks to the call indexes in erigon, the query performance for large block ranges is pretty amazing. Unfortunately, I couldn't find such an index in op-geth's code base so this will result in way slower response times for bigger block ranges because all blocks from a given range will be simulated. But once we build such an index, it's an easy fix 🦾

Would be great if someone could review this and lmk if anything needs to be adapted.

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.

1 participant