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

Undo transactions #2041

Open
nicedinner opened this issue Oct 28, 2021 · 2 comments
Open

Undo transactions #2041

nicedinner opened this issue Oct 28, 2021 · 2 comments

Comments

@nicedinner
Copy link

I'm trying to test smart contract security issues with py-evm. Suppose i execute a set of transactions, check out the contract state after the transactions and find no loophole triggered. The problem is how can i undo the latest one or two executed transactions (for further test)? Or, how can i set the chain state to the precise state where several designated transactions are executed?

Hope to know, thanks a lot!

@fjarri
Copy link

fjarri commented Feb 9, 2024

Looking for a similar functionality, basically saving/restoring snapshots of the chain state. eth-tester is doing it via some undocumented API:

# revert the state to `block_hash`
block = chain.get_block_by_hash(block_hash)
chaindb = chain.chaindb

chaindb._set_as_canonical_chain_head(chaindb.db, block.header, eth.constants.GENESIS_PARENT_HASH)
if block.number > 0:
    chain.import_block(block)
else:
    chain = chain.from_genesis_header(chaindb.db, block.header)

This works, but it doesn't restore the state of pending transactions (if any), and it uses a private method, so it can break at any moment, and cannot be typechecked. I wonder if there's an official way of doing snapshots?

@fjarri
Copy link

fjarri commented Apr 1, 2024

In case anyone bumps into this issue, I've pivoted to just copy the chain via eth.tools.builder.chain.copy(). Copies the pending transactions as well. Hopefully it's supposed to be public API and is not going away.

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

No branches or pull requests

2 participants