mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-17 21:46:36 +00:00
cmd/evm/internal/t8ntool: fix eof checks
This commit is contained in:
parent
a4c40781a8
commit
97bb2a5d5a
5 changed files with 14 additions and 14 deletions
|
|
@ -270,11 +270,11 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error {
|
||||||
|
|
||||||
// applyEOFChecks does a sanity check of the prestate EOF code validity, to avoid panic during state transition.
|
// applyEOFChecks does a sanity check of the prestate EOF code validity, to avoid panic during state transition.
|
||||||
func applyEOFChecks(prestate *Prestate, chainConfig *params.ChainConfig) error {
|
func applyEOFChecks(prestate *Prestate, chainConfig *params.ChainConfig) error {
|
||||||
if !chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) {
|
if !chainConfig.IsOsaka(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for addr, acc := range prestate.Pre {
|
for addr, acc := range prestate.Pre {
|
||||||
if vm.HasEOFByte(acc.Code) {
|
if vm.HasEOFMagic(acc.Code) {
|
||||||
var (
|
var (
|
||||||
c vm.Container
|
c vm.Container
|
||||||
err error
|
err error
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,13 @@ const (
|
||||||
|
|
||||||
var eofMagic = []byte{0xef, 0x00}
|
var eofMagic = []byte{0xef, 0x00}
|
||||||
|
|
||||||
// HasEOFByte returns true if code starts with 0xEF byte
|
// hasEOFByte returns true if code starts with 0xEF byte
|
||||||
func HasEOFByte(code []byte) bool {
|
func hasEOFByte(code []byte) bool {
|
||||||
return len(code) != 0 && code[0] == eofFormatByte
|
return len(code) != 0 && code[0] == eofFormatByte
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasEOFMagic returns true if code starts with magic defined by EIP-3540
|
// HasEOFMagic returns true if code starts with magic defined by EIP-3540
|
||||||
func hasEOFMagic(code []byte) bool {
|
func HasEOFMagic(code []byte) bool {
|
||||||
return len(eofMagic) <= len(code) && bytes.Equal(eofMagic, code[0:len(eofMagic)])
|
return len(eofMagic) <= len(code) && bytes.Equal(eofMagic, code[0:len(eofMagic)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ func (c *Container) UnmarshalSubContainer(b []byte, isInitcode bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) unmarshalContainer(b []byte, isInitcode bool, topLevel bool) error {
|
func (c *Container) unmarshalContainer(b []byte, isInitcode bool, topLevel bool) error {
|
||||||
if !hasEOFMagic(b) {
|
if !HasEOFMagic(b) {
|
||||||
return fmt.Errorf("%w: want %x", errInvalidMagic, eofMagic)
|
return fmt.Errorf("%w: want %x", errInvalidMagic, eofMagic)
|
||||||
}
|
}
|
||||||
if len(b) < 14 {
|
if len(b) < 14 {
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ func opExtDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCont
|
||||||
returnGas uint64
|
returnGas uint64
|
||||||
)
|
)
|
||||||
code := interpreter.evm.StateDB.GetCode(toAddr)
|
code := interpreter.evm.StateDB.GetCode(toAddr)
|
||||||
if !hasEOFMagic(code) {
|
if !HasEOFMagic(code) {
|
||||||
// Delegate-calling a non-eof contract should return 1
|
// Delegate-calling a non-eof contract should return 1
|
||||||
err = ErrExecutionReverted
|
err = ErrExecutionReverted
|
||||||
ret = nil
|
ret = nil
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address,
|
||||||
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
|
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
|
||||||
} else {
|
} else {
|
||||||
code := evm.StateDB.GetCode(addr)
|
code := evm.StateDB.GetCode(addr)
|
||||||
if fromEOF && !hasEOFMagic(code) {
|
if fromEOF && !HasEOFMagic(code) {
|
||||||
return nil, gas, errors.New("extDelegateCall to non-eof contract")
|
return nil, gas, errors.New("extDelegateCall to non-eof contract")
|
||||||
}
|
}
|
||||||
// Initialise a new contract and make initialise the delegate values
|
// Initialise a new contract and make initialise the delegate values
|
||||||
|
|
@ -442,7 +442,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui
|
||||||
contract.IsDeployment = true
|
contract.IsDeployment = true
|
||||||
|
|
||||||
// Validate initcode per EOF rules. If caller is EOF and initcode is legacy, fail.
|
// Validate initcode per EOF rules. If caller is EOF and initcode is legacy, fail.
|
||||||
isInitcodeEOF := hasEOFMagic(code)
|
isInitcodeEOF := HasEOFMagic(code)
|
||||||
if isInitcodeEOF {
|
if isInitcodeEOF {
|
||||||
if allowEOF {
|
if allowEOF {
|
||||||
// If the initcode is EOF, verify it is well-formed.
|
// If the initcode is EOF, verify it is well-formed.
|
||||||
|
|
@ -556,16 +556,16 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address, isIn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject legacy contract deployment from EOF.
|
// Reject legacy contract deployment from EOF.
|
||||||
if isInitcodeEOF && !hasEOFMagic(ret) {
|
if isInitcodeEOF && !HasEOFMagic(ret) {
|
||||||
return ret, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode)
|
return ret, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode)
|
||||||
}
|
}
|
||||||
// Reject EOF deployment from legacy.
|
// Reject EOF deployment from legacy.
|
||||||
if !isInitcodeEOF && hasEOFMagic(ret) {
|
if !isInitcodeEOF && HasEOFMagic(ret) {
|
||||||
return ret, ErrLegacyCode
|
return ret, ErrLegacyCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject code starting with 0xEF if EIP-3541 is enabled.
|
// Reject code starting with 0xEF if EIP-3541 is enabled.
|
||||||
if len(ret) >= 1 && HasEOFByte(ret) {
|
if len(ret) >= 1 && hasEOFByte(ret) {
|
||||||
if evm.chainRules.IsOsaka && isInitcodeEOF {
|
if evm.chainRules.IsOsaka && isInitcodeEOF {
|
||||||
// Don't reject EOF contracts after Osaka
|
// Don't reject EOF contracts after Osaka
|
||||||
} else if evm.chainRules.IsLondon {
|
} else if evm.chainRules.IsLondon {
|
||||||
|
|
|
||||||
|
|
@ -442,7 +442,7 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
} else {
|
} else {
|
||||||
// TODO this should not need to pull up the whole code
|
// TODO this should not need to pull up the whole code
|
||||||
code := interpreter.evm.StateDB.GetCode(address)
|
code := interpreter.evm.StateDB.GetCode(address)
|
||||||
if HasEOFByte(code) {
|
if HasEOFMagic(code) {
|
||||||
slot.SetFromHex("0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5")
|
slot.SetFromHex("0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5")
|
||||||
} else {
|
} else {
|
||||||
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(address).Bytes())
|
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(address).Bytes())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue