Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/vm: EXTCODE* return delegation designator for 7702 #31089

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -707,65 +705,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