onflow / flow-go

A fast, secure, and developer-friendly blockchain built to support the next generation of games, apps, and the digital assets that power them.
GNU Affero General Public License v3.0
530 stars 176 forks source link

Validate GW re-executing works flawless #6552

Open ramtinms opened 2 weeks ago

ramtinms commented 2 weeks ago

Problem Definition

We need to check if the GW can re-execute all transactions since day 0 given changes to the EVM contracts. There has been some changes in the past to event formats and we didn't have the checksum early days. This is a one time task given we have checksums going forward.

Two challenges are

Proposed Solution

We need to test re-executing and comparing the final registers against what can be extracted from an EN state snapshot. Then we can validate if we need to backfill the prerandao values if are missing or if there is any flaw in re-execution.

Some info

Sample cli query flow events get A.8c5303eaa26202d6.EVM.TransactionExecuted A.8c5303eaa26202d6.EVM.BlockExecuted --start 211176670 --end 211176770 --network testnet --host access-001.devnet51.nodes.onflow.org:9000

flow events get A.e467b9dd11fa00df.EVM.TransactionExecuted A.e467b9dd11fa00df.EVM.BlockExecuted --start 88226267 --end 88226367 --network mainnet

ramtinms commented 8 hours ago

copy of my notes sent earlier on the slack:

I fetched and sorted all the events for the previous sporks and you can do download them here (the fetch code is also gonna be a PR soon) . https://storage.googleapis.com/flow-benchmark-experiments/evm/devnet51_evm_events.jsonl https://storage.googleapis.com/flow-benchmark-experiments/evm/mainnet25%20_evm_events.jsonl 10:44 I tried to re-execute all transactions and for mainnet 25 it was successfully re-executing all 10:48 for devnet we had couple of issues that I resolved but there is still one transaction that is reporting using less gas than what was included in the event. https://evm-testnet.flowscan.io/tx/0xc409a69ed5144f9d978c16d5243e7855d399afbf6e7f5c6e3f4b4f19a82abafe?tab=index I checked it and is a regular evm transaction trying to deploy a contract, the deployed contract is identical but the event is reporting 3792644 gas consumed, but on re-execution we are getting 3772744 gas consumed tx Hash: c409a69ed5144f9d978c16d5243e7855d399afbf6e7f5c6e3f4b4f19a82abafe Network: devnet51 Flow block height: 217735938 So far my gut feeling is we might have deployed some configs or versions on the HCU 2 of devnet that based on the different config leads to different gas cost for new deployment. as soon as the PR above is merged, I’m going to backport it to the branch v0.37.10 and test re-execution again.

evm-testnet.flowscan.ioevm-testnet.flowscan.io EVM on Flow (testnet) transaction 0xc409a69ed5144f9d978c16d5243e7855d399afbf6e7f5c6e3f4b4f19a82abafe

considerations: Since before the current spork we didn’t have state update checksum, I added a way to export the EVM state (ignoring what is the underlying ledger structure) https://github.com/onflow/flow-go/pull/6555 This should help us to export the EVM state at the start of the spork and compare it with the one after re-execution of all previous transactions on previous sporks

this way we can verify the correctness of the full state and going forward the state update checksum validates the state changes when we re-execute transactions on the GW nodes 10:53 When replay functionality is validated this PR can be used https://github.com/onflow/flow-go/pull/6546 to let eth_calls possible offchain. Only remaining issue is dealing with gas cost as its using direct call right now and we might need to provided a way to support gas fee for a direct call.

bluesign commented 7 hours ago

I checked it and is a regular evm transaction trying to deploy a contract, the deployed contract is identical but the event is reporting 3792644 gas consumed, but on re-execution we are getting 3772744 gas consumed

was there any gas refund change? 19900 is related to slot update logic and gas refund https://github.com/wolflo/evm-opcodes/blob/main/gas.md