From c86093a934c148bbda4399a20fd13f2d7eebc04d Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 23 Mar 2026 20:55:07 +0800 Subject: [PATCH] core: remove block number assignment in log --- core/evm.go | 4 ++-- core/state_processor.go | 2 +- core/types/log.go | 12 ++---------- core/vm/evm.go | 6 +++--- core/vm/gas_table_test.go | 4 ++-- core/vm/instructions.go | 7 ++----- core/vm/interpreter_test.go | 2 +- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/core/evm.go b/core/evm.go index c79ef205cf..818b23bee5 100644 --- a/core/evm.go +++ b/core/evm.go @@ -139,10 +139,10 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *uint256.Int) bool { } // Transfer subtracts amount from sender and adds amount to recipient using the given Db -func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int, blockNumber *big.Int, rules *params.Rules) { +func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int, rules *params.Rules) { db.SubBalance(sender, amount, tracing.BalanceChangeTransfer) db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer) if rules.IsAmsterdam && !amount.IsZero() && sender != recipient { - db.AddLog(types.EthTransferLog(blockNumber, sender, recipient, amount)) + db.AddLog(types.EthTransferLog(sender, recipient, amount)) } } diff --git a/core/state_processor.go b/core/state_processor.go index 6fd4372fa7..80f1b6818b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -176,7 +176,7 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) { // Emit burn logs where accounts with non-empty balances have been deleted for _, sd := range statedb.GetRemovedAccountsWithBalance() { - statedb.AddLog(types.EthBurnLog(blockNumber, sd.Address, sd.Balance)) + statedb.AddLog(types.EthBurnLog(sd.Address, sd.Balance)) } } // Update the state with pending changes. diff --git a/core/types/log.go b/core/types/log.go index 33599503d9..487ca57b5a 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -17,8 +17,6 @@ package types import ( - "math/big" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/params" @@ -69,7 +67,7 @@ type logMarshaling struct { // EthTransferLog creates and ETH transfer log according to EIP-7708. // Specification: https://eips.ethereum.org/EIPS/eip-7708 -func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log { +func EthTransferLog(from, to common.Address, amount *uint256.Int) *Log { amount32 := amount.Bytes32() return &Log{ Address: params.SystemAddress, @@ -79,15 +77,12 @@ func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint2 common.BytesToHash(to.Bytes()), }, Data: amount32[:], - // This is a non-consensus field, but assigned here because - // core/state doesn't know the current block number. - BlockNumber: blockNumber.Uint64(), } } // EthBurnLog creates an ETH burn log according to EIP-7708. // Specification: https://eips.ethereum.org/EIPS/eip-7708 -func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log { +func EthBurnLog(from common.Address, amount *uint256.Int) *Log { amount32 := amount.Bytes32() return &Log{ Address: params.SystemAddress, @@ -96,8 +91,5 @@ func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) common.BytesToHash(from.Bytes()), }, Data: amount32[:], - // This is a non-consensus field, but assigned here because - // core/state doesn't know the current block number. - BlockNumber: blockNumber.Uint64(), } } diff --git a/core/vm/evm.go b/core/vm/evm.go index 464c062ee2..36494de2a8 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -35,7 +35,7 @@ type ( // CanTransferFunc is the signature of a transfer guard function CanTransferFunc func(StateDB, common.Address, *uint256.Int) bool // TransferFunc is the signature of a transfer function - TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) + TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) // GetHashFunc returns the n'th block hash in the blockchain // and is used by the BLOCKHASH EVM op code. GetHashFunc func(uint64) common.Hash @@ -283,7 +283,7 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g // Calling this is required even for zero-value transfers, // to ensure the state clearing mechanism is applied. if !syscall { - evm.Context.Transfer(evm.StateDB, caller, addr, value, evm.Context.BlockNumber, &evm.chainRules) + evm.Context.Transfer(evm.StateDB, caller, addr, value, &evm.chainRules) } if isPrecompile { @@ -568,7 +568,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui } gas = gas - consumed } - evm.Context.Transfer(evm.StateDB, caller, address, value, evm.Context.BlockNumber, &evm.chainRules) + evm.Context.Transfer(evm.StateDB, caller, address, value, &evm.chainRules) // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. diff --git a/core/vm/gas_table_test.go b/core/vm/gas_table_test.go index b72b68cff2..e9e56038dd 100644 --- a/core/vm/gas_table_test.go +++ b/core/vm/gas_table_test.go @@ -94,7 +94,7 @@ func TestEIP2200(t *testing.T) { vmctx := BlockContext{ CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true }, - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {}, } evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}}) @@ -144,7 +144,7 @@ func TestCreateGas(t *testing.T) { statedb.Finalise(true) vmctx := BlockContext{ CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true }, - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {}, BlockNumber: big.NewInt(0), } config := Config{} diff --git a/core/vm/instructions.go b/core/vm/instructions.go index ee809d1d19..a5fa11e307 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -936,9 +936,9 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro } if evm.chainRules.IsAmsterdam && !balance.IsZero() { if this != beneficiary { - evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) + evm.StateDB.AddLog(types.EthTransferLog(this, beneficiary, balance)) } else if newContract { - evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance)) + evm.StateDB.AddLog(types.EthBurnLog(this, balance)) } } @@ -1093,9 +1093,6 @@ func makeLog(size int) executionFunc { Address: scope.Contract.Address(), Topics: topics, Data: d, - // This is a non-consensus field, but assigned here because - // core/state doesn't know the current block number. - BlockNumber: evm.Context.BlockNumber.Uint64(), }) return nil, nil diff --git a/core/vm/interpreter_test.go b/core/vm/interpreter_test.go index f0bf9cf1e4..28df8546b5 100644 --- a/core/vm/interpreter_test.go +++ b/core/vm/interpreter_test.go @@ -40,7 +40,7 @@ var loopInterruptTests = []string{ func TestLoopInterrupt(t *testing.T) { address := common.BytesToAddress([]byte("contract")) vmctx := BlockContext{ - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {}, } for i, tt := range loopInterruptTests {