Skip to content

Commit fdfc159

Browse files
committed
core/vm: return delegation designator prefix for code reading ops
1 parent 7ecda7d commit fdfc159

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

core/vm/eips.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/core/tracing"
26+
"github.com/ethereum/go-ethereum/core/types"
27+
"github.com/ethereum/go-ethereum/crypto"
2628
"github.com/ethereum/go-ethereum/params"
2729
"github.com/holiman/uint256"
2830
)
@@ -718,8 +720,10 @@ func opExtCodeCopyEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeC
718720
if overflow {
719721
uint64CodeOffset = math.MaxUint64
720722
}
721-
addr := common.Address(a.Bytes20())
722-
code := interpreter.evm.resolveCode(addr)
723+
code := interpreter.evm.StateDB.GetCode(common.Address(a.Bytes20()))
724+
if _, ok := types.ParseDelegation(code); ok {
725+
code = types.DelegationPrefix[:2]
726+
}
723727
codeCopy := getData(code, uint64CodeOffset, length.Uint64())
724728
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
725729

@@ -729,18 +733,29 @@ func opExtCodeCopyEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeC
729733
// opExtCodeSizeEIP7702 implements the EIP-7702 variation of opExtCodeSize.
730734
func opExtCodeSizeEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
731735
slot := scope.Stack.peek()
732-
slot.SetUint64(uint64(len(interpreter.evm.resolveCode(slot.Bytes20()))))
736+
code := interpreter.evm.StateDB.GetCode(common.Address(slot.Bytes20()))
737+
if _, ok := types.ParseDelegation(code); ok {
738+
code = types.DelegationPrefix[:2]
739+
}
740+
slot.SetUint64(uint64(len(code)))
733741
return nil, nil
734742
}
735743

736744
// opExtCodeHashEIP7702 implements the EIP-7702 variation of opExtCodeHash.
737745
func opExtCodeHashEIP7702(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
738746
slot := scope.Stack.peek()
739-
address := common.Address(slot.Bytes20())
740-
if interpreter.evm.StateDB.Empty(address) {
747+
addr := common.Address(slot.Bytes20())
748+
if interpreter.evm.StateDB.Empty(addr) {
741749
slot.Clear()
750+
return nil, nil
751+
}
752+
code := interpreter.evm.StateDB.GetCode(addr)
753+
if _, ok := types.ParseDelegation(code); ok {
754+
// If the code is a delegation, return the prefix without version.
755+
slot.SetBytes(crypto.Keccak256(types.DelegationPrefix[:2]))
742756
} else {
743-
slot.SetBytes(interpreter.evm.resolveCodeHash(address).Bytes())
757+
// Otherwise, return normal code hash.
758+
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(addr).Bytes())
744759
}
745760
return nil, nil
746761
}

core/vm/evm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ func (evm *EVM) resolveCode(addr common.Address) []byte {
583583

584584
// resolveCodeHash returns the code hash associated with the provided address.
585585
// After Prague, it can also resolve code hash of the account pointed to by a
586-
// delegation designator.
586+
// delegation designator. Although this is not accessible in the EVM it is used
587+
// internally to associate jumpdest analysis to code.
587588
func (evm *EVM) resolveCodeHash(addr common.Address) common.Hash {
588589
if evm.chainRules.IsPrague {
589590
code := evm.StateDB.GetCode(addr)

0 commit comments

Comments
 (0)