mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core, consensus, params: rework the 7997 a bit
This commit is contained in:
parent
47c1f0d390
commit
5fecc3facb
5 changed files with 13 additions and 17 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue