mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16: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
|
package misc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"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/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"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
|
// ApplyEIP7997 inserts the deterministic deployment factory into the state as an
|
||||||
// irregular state transition, as specified by EIP-7997. The factory is a keyless
|
// 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,
|
// CREATE2 factory that, once present at the canonical address on every EVM chain,
|
||||||
// allows contracts to be deployed at identical addresses across chains.
|
// allows contracts to be deployed at identical addresses across chains.
|
||||||
func ApplyEIP7997(statedb vm.StateDB) {
|
func ApplyEIP7997(statedb vm.StateDB) {
|
||||||
// If the canonical factory is already in place there is nothing to do.
|
contractHash := statedb.GetCodeHash(params.DeterministicFactoryAddress)
|
||||||
if statedb.GetCodeHash(params.DeterministicFactoryAddress) == deterministicFactoryCodeHash {
|
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
|
return
|
||||||
}
|
}
|
||||||
if !statedb.Exist(params.DeterministicFactoryAddress) {
|
if !statedb.Exist(params.DeterministicFactoryAddress) {
|
||||||
|
|
@ -41,5 +42,5 @@ func ApplyEIP7997(statedb vm.StateDB) {
|
||||||
}
|
}
|
||||||
statedb.CreateContract(params.DeterministicFactoryAddress)
|
statedb.CreateContract(params.DeterministicFactoryAddress)
|
||||||
statedb.SetCode(params.DeterministicFactoryAddress, params.DeterministicFactoryCode, tracing.CodeChangeUnspecified)
|
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) {
|
if got := sdb.GetCode(params.DeterministicFactoryAddress); !bytes.Equal(got, params.DeterministicFactoryCode) {
|
||||||
t.Fatalf("factory code mismatch:\n got %x\nwant %x", 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 {
|
if got := sdb.GetNonce(params.DeterministicFactoryAddress); got != 1 {
|
||||||
t.Fatalf("factory nonce = %d, want %d", got, params.DeterministicFactoryNonce)
|
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.BuilderDepositAddress: {Nonce: 1, Code: params.BuilderDepositCode, Balance: common.Big0},
|
||||||
params.BuilderExitAddress: {Nonce: 1, Code: params.BuilderExitCode, Balance: common.Big0},
|
params.BuilderExitAddress: {Nonce: 1, Code: params.BuilderExitCode, Balance: common.Big0},
|
||||||
// EIP-7997 - Deterministic deployment factory
|
// 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 {
|
if faucet != nil {
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,10 @@ func (p *StateProcessor) Process(ctx context.Context, block *types.Block, stated
|
||||||
blockAccessList = bal.NewConstructionBlockAccessList()
|
blockAccessList = bal.NewConstructionBlockAccessList()
|
||||||
)
|
)
|
||||||
defer evm.Release()
|
defer evm.Release()
|
||||||
|
|
||||||
if jumpDestCache != nil {
|
if jumpDestCache != nil {
|
||||||
evm.SetJumpDestCache(jumpDestCache)
|
evm.SetJumpDestCache(jumpDestCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the pre-execution system calls
|
// Run the pre-execution system calls
|
||||||
blockAccessList.Merge(PreExecution(ctx, block.BeaconRoot(), block.ParentHash(), config, evm, block.Number(), block.Time()))
|
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)
|
// EIP-7997 - Deterministic deployment factory (keyless CREATE2 factory)
|
||||||
DeterministicFactoryAddress = common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C")
|
DeterministicFactoryAddress = common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C")
|
||||||
DeterministicFactoryCode = common.FromHex("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3")
|
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.
|
// System log events.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue