Skip to content

Commit

Permalink
core/vm: EXTCODE* return delegation designator for 7702 (#31089)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na authored Jan 30, 2025
1 parent 0e1a19d commit a50cac5
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a50cac5

Please sign in to comment.