core/vm: EXTCODE* return delegation designator for 7702 (#31089)
Implements https://github.com/ethereum/EIPs/pull/9248
This commit is contained in:
parent
0e1a19da76
commit
a50cac5bbe
|
@ -23,8 +23,6 @@ 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/crypto"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
@ -709,65 +707,8 @@ func enableEOF(jt *JumpTable) {
|
|||
}
|
||||
}
|
||||
|
||||
// opExtCodeCopyEIP7702 implements the EIP-7702 variation of opExtCodeCopy.
|
||||
func opExtCodeCopyEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
var (
|
||||
stack = scope.Stack
|
||||
a = stack.pop()
|
||||
memOffset = stack.pop()
|
||||
codeOffset = stack.pop()
|
||||
length = stack.pop()
|
||||
)
|
||||
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
||||
if overflow {
|
||||
uint64CodeOffset = math.MaxUint64
|
||||
}
|
||||
code := interpreter.evm.StateDB.GetCode(common.Address(a.Bytes20()))
|
||||
if _, ok := types.ParseDelegation(code); ok {
|
||||
code = types.DelegationPrefix[:2]
|
||||
}
|
||||
codeCopy := getData(code, uint64CodeOffset, length.Uint64())
|
||||
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// opExtCodeSizeEIP7702 implements the EIP-7702 variation of opExtCodeSize.
|
||||
func opExtCodeSizeEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
slot := scope.Stack.peek()
|
||||
code := interpreter.evm.StateDB.GetCode(common.Address(slot.Bytes20()))
|
||||
if _, ok := types.ParseDelegation(code); ok {
|
||||
code = types.DelegationPrefix[:2]
|
||||
}
|
||||
slot.SetUint64(uint64(len(code)))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// opExtCodeHashEIP7702 implements the EIP-7702 variation of opExtCodeHash.
|
||||
func opExtCodeHashEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
slot := scope.Stack.peek()
|
||||
addr := common.Address(slot.Bytes20())
|
||||
if interpreter.evm.StateDB.Empty(addr) {
|
||||
slot.Clear()
|
||||
return nil, nil
|
||||
}
|
||||
code := interpreter.evm.StateDB.GetCode(addr)
|
||||
if _, ok := types.ParseDelegation(code); ok {
|
||||
// If the code is a delegation, return the prefix without version.
|
||||
slot.SetBytes(crypto.Keccak256(types.DelegationPrefix[:2]))
|
||||
} else {
|
||||
// Otherwise, return normal code hash.
|
||||
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(addr).Bytes())
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// enable7702 the EIP-7702 changes to support delegation designators.
|
||||
func enable7702(jt *JumpTable) {
|
||||
jt[EXTCODECOPY].execute = opExtCodeCopyEIP7702
|
||||
jt[EXTCODESIZE].execute = opExtCodeSizeEIP7702
|
||||
jt[EXTCODEHASH].execute = opExtCodeHashEIP7702
|
||||
|
||||
jt[CALL].dynamicGas = gasCallEIP7702
|
||||
jt[CALLCODE].dynamicGas = gasCallCodeEIP7702
|
||||
jt[STATICCALL].dynamicGas = gasStaticCallEIP7702
|
||||
|
|
Loading…
Reference in New Issue