diff --git a/eth/tracers/internal/tracetest/calltrace_test.go b/eth/tracers/internal/tracetest/calltrace_test.go index e97023825e..4f382038e1 100644 --- a/eth/tracers/internal/tracetest/calltrace_test.go +++ b/eth/tracers/internal/tracetest/calltrace_test.go @@ -117,8 +117,8 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) { // Configure a blockchain with the given prestate var ( signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time)) - context = test.Context.toBlockContext(test.Genesis) state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme) + context = test.Context.toBlockContext(test.Genesis, state.StateDB) ) state.Close() diff --git a/eth/tracers/internal/tracetest/flat_calltrace_test.go b/eth/tracers/internal/tracetest/flat_calltrace_test.go index 050950c864..7f0bc57d21 100644 --- a/eth/tracers/internal/tracetest/flat_calltrace_test.go +++ b/eth/tracers/internal/tracetest/flat_calltrace_test.go @@ -83,8 +83,8 @@ func flatCallTracerTestRunner(tracerName string, filename string, dirPath string return fmt.Errorf("failed to parse testcase input: %v", err) } signer := types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time)) - context := test.Context.toBlockContext(test.Genesis) state := tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme) + context := test.Context.toBlockContext(test.Genesis, state.StateDB) defer state.Close() // Create the tracer, the EVM environment and run it diff --git a/eth/tracers/internal/tracetest/prestate_test.go b/eth/tracers/internal/tracetest/prestate_test.go index 9cbd126694..bab6e676db 100644 --- a/eth/tracers/internal/tracetest/prestate_test.go +++ b/eth/tracers/internal/tracetest/prestate_test.go @@ -93,8 +93,8 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) { // Configure a blockchain with the given prestate var ( signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time)) - context = test.Context.toBlockContext(test.Genesis) state = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme) + context = test.Context.toBlockContext(test.Genesis, state.StateDB) ) defer state.Close() diff --git a/eth/tracers/internal/tracetest/testdata/prestate_tracer_with_diff_mode/optimism.json b/eth/tracers/internal/tracetest/testdata/prestate_tracer_with_diff_mode/optimism.json new file mode 100644 index 0000000000..1f2767d6da --- /dev/null +++ b/eth/tracers/internal/tracetest/testdata/prestate_tracer_with_diff_mode/optimism.json @@ -0,0 +1,94 @@ +{ + "genesis": { + "baseFeePerGas": "1000000000", + "blobGasUsed": "0", + "difficulty": "0", + "excessBlobGas": "0", + "extraData": "0x", + "gasLimit": "11500000", + "hash": "0x4a3a3699d4d328652bfea00c9fdc2be4768519142e10e0d6cebdbec5056f101e", + "miner": "0x0000000000000000000000000000000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000000", + "number": "0", + "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "stateRoot": "0x0344388281802511fb31b24f96f087a8b935683646d2a75de96465703505e065", + "timestamp": "0", + "withdrawals": [], + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "alloc": { + "0x0000000000000000000000000000000000000000": { + "balance": "0x0" + }, + "0xf7b094d8c987eff69afec8f93153ac9829577125": { + "balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7" + } + }, + "config": { + "chainId": 1337, + "homesteadBlock": 0, + "eip150Block": 0, + "eip155Block": 0, + "eip158Block": 0, + "byzantiumBlock": 0, + "constantinopleBlock": 0, + "petersburgBlock": 0, + "istanbulBlock": 0, + "muirGlacierBlock": 0, + "berlinBlock": 0, + "londonBlock": 0, + "arrowGlacierBlock": 0, + "grayGlacierBlock": 0, + "bedrockBlock": 0, + "shanghaiTime": 0, + "cancunTime": 0, + "terminalTotalDifficulty": 0, + "terminalTotalDifficultyPassed": true, + "depositContractAddress": "0x0000000000000000000000000000000000000000", + "optimism": { + "eip1559Elasticity": 6, + "eip1559Denominator": 50, + "eip1559DenominatorCanyon": 250 + } + } + }, + "context": { + "number": "1", + "difficulty": "0", + "timestamp": "1729512767", + "gasLimit": "11511229", + "miner": "0x0000000000000000000000000000000000000000", + "baseFeePerGas": "875000000", + "random": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "random": "0x0000000000000000000000000000000000000000000000000000000000000000", + "input": "0x02f8708205398001847735940182520894f7b094d8c987eff69afec8f93153ac9829577125880de0b6b3a764000080c001a0e44882c072410fbadfd4783a71be745edfcedd9fc9ab55b66e25bb039db2f579a017c13129640ceff7ffa674bcff74bcce168404aa8450a67ece2737ca5a554a12", + "result": { + "post": { + "0x0000000000000000000000000000000000000000": { + "balance": "0x5208" + }, + "0x4200000000000000000000000000000000000019": { + "balance": "0x10b643590600" + }, + "0xf7b094d8c987eff69afec8f93153ac9829577125": { + "balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffef49bca6a7ef", + "nonce": 1 + } + }, + "pre": { + "0x0000000000000000000000000000000000000000": { + "balance": "0x0" + }, + "0x4200000000000000000000000000000000000019": { + "balance": "0x0" + }, + "0xf7b094d8c987eff69afec8f93153ac9829577125": { + "balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7" + } + } + }, + "tracerConfig": { + "diffMode": true + } +} diff --git a/eth/tracers/internal/tracetest/util.go b/eth/tracers/internal/tracetest/util.go index a74a96f8a4..9e647d5b1e 100644 --- a/eth/tracers/internal/tracetest/util.go +++ b/eth/tracers/internal/tracetest/util.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" // Force-load native and js packages, to trigger registration @@ -34,7 +35,7 @@ type callContext struct { BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` } -func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext { +func (c *callContext) toBlockContext(genesis *core.Genesis, statedb types.StateGetter) vm.BlockContext { context := vm.BlockContext{ CanTransfer: core.CanTransfer, Transfer: core.Transfer, @@ -43,6 +44,8 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext { Time: uint64(c.Time), Difficulty: (*big.Int)(c.Difficulty), GasLimit: uint64(c.GasLimit), + Random: &genesis.Mixhash, + L1CostFunc: types.NewL1CostFunc(genesis.Config, statedb), } if genesis.Config.IsLondon(context.BlockNumber) { context.BaseFee = (*big.Int)(c.BaseFee) diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index b353c06960..3e966e2dc7 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/eth/tracers/internal" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" ) //go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go @@ -158,6 +159,9 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction t.lookupAccount(from) t.lookupAccount(t.to) t.lookupAccount(env.Coinbase) + if env.ChainConfig.Optimism != nil { + t.lookupAccount(params.OptimismBaseFeeRecipient) + } } func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {