From 5fecc3facb7af624119776fdb6ff3bf932eb45ca Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 2 Jul 2026 09:24:58 +0800 Subject: [PATCH] core, consensus, params: rework the 7997 a bit --- consensus/misc/eip7997.go | 17 +++++++++-------- core/eip7997_test.go | 4 ++-- core/genesis.go | 2 +- core/state_processor.go | 2 +- params/protocol_params.go | 5 ----- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/consensus/misc/eip7997.go b/consensus/misc/eip7997.go index d117bfe469..e01c099638 100644 --- a/consensus/misc/eip7997.go +++ b/consensus/misc/eip7997.go @@ -17,23 +17,24 @@ package misc import ( + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/tracing" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" ) -// deterministicFactoryCodeHash is the keccak256 of the canonical factory code, -// used to detect an already-deployed factory. -var deterministicFactoryCodeHash = crypto.Keccak256Hash(params.DeterministicFactoryCode) - // ApplyEIP7997 inserts the deterministic deployment factory into the state as an // irregular state transition, as specified by EIP-7997. The factory is a keyless // CREATE2 factory that, once present at the canonical address on every EVM chain, // allows contracts to be deployed at identical addresses across chains. func ApplyEIP7997(statedb vm.StateDB) { - // If the canonical factory is already in place there is nothing to do. - if statedb.GetCodeHash(params.DeterministicFactoryAddress) == deterministicFactoryCodeHash { + contractHash := statedb.GetCodeHash(params.DeterministicFactoryAddress) + nonce := statedb.GetNonce(params.DeterministicFactoryAddress) + + // Reject the irregular state transition if the destination doesn't + // satisfy the deployment condition. + if nonce != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) { return } if !statedb.Exist(params.DeterministicFactoryAddress) { @@ -41,5 +42,5 @@ func ApplyEIP7997(statedb vm.StateDB) { } statedb.CreateContract(params.DeterministicFactoryAddress) statedb.SetCode(params.DeterministicFactoryAddress, params.DeterministicFactoryCode, tracing.CodeChangeUnspecified) - statedb.SetNonce(params.DeterministicFactoryAddress, params.DeterministicFactoryNonce, tracing.NonceChangeNewContract) + statedb.SetNonce(params.DeterministicFactoryAddress, 1, tracing.NonceChangeNewContract) } diff --git a/core/eip7997_test.go b/core/eip7997_test.go index 3f9cbde187..3922d78b1c 100644 --- a/core/eip7997_test.go +++ b/core/eip7997_test.go @@ -41,8 +41,8 @@ func TestApplyEIP7997(t *testing.T) { if got := sdb.GetCode(params.DeterministicFactoryAddress); !bytes.Equal(got, params.DeterministicFactoryCode) { t.Fatalf("factory code mismatch:\n got %x\nwant %x", got, params.DeterministicFactoryCode) } - if got := sdb.GetNonce(params.DeterministicFactoryAddress); got != params.DeterministicFactoryNonce { - t.Fatalf("factory nonce = %d, want %d", got, params.DeterministicFactoryNonce) + if got := sdb.GetNonce(params.DeterministicFactoryAddress); got != 1 { + t.Fatalf("factory nonce = %d, want %d", got, 1) } } diff --git a/core/genesis.go b/core/genesis.go index a63b06c261..df18a274b8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -722,7 +722,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis { params.BuilderDepositAddress: {Nonce: 1, Code: params.BuilderDepositCode, Balance: common.Big0}, params.BuilderExitAddress: {Nonce: 1, Code: params.BuilderExitCode, Balance: common.Big0}, // EIP-7997 - Deterministic deployment factory - params.DeterministicFactoryAddress: {Nonce: params.DeterministicFactoryNonce, Code: params.DeterministicFactoryCode, Balance: common.Big0}, + params.DeterministicFactoryAddress: {Nonce: 1, Code: params.DeterministicFactoryCode, Balance: common.Big0}, }, } if faucet != nil { diff --git a/core/state_processor.go b/core/state_processor.go index 4575c39223..bc565db6f9 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -93,10 +93,10 @@ func (p *StateProcessor) Process(ctx context.Context, block *types.Block, stated blockAccessList = bal.NewConstructionBlockAccessList() ) defer evm.Release() + if jumpDestCache != nil { evm.SetJumpDestCache(jumpDestCache) } - // Run the pre-execution system calls blockAccessList.Merge(PreExecution(ctx, block.BeaconRoot(), block.ParentHash(), config, evm, block.Number(), block.Time())) diff --git a/params/protocol_params.go b/params/protocol_params.go index 7580713d66..22e5fd3624 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -250,11 +250,6 @@ var ( // EIP-7997 - Deterministic deployment factory (keyless CREATE2 factory) DeterministicFactoryAddress = common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C") DeterministicFactoryCode = common.FromHex("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3") - - // DeterministicFactoryNonce is the nonce the factory account carries, matching - // the keyless deployment transaction that originally created it (nonce 0 of the - // deployer, leaving the factory itself at nonce 1). - DeterministicFactoryNonce = uint64(1) ) // System log events.