Skip to content

Commit

Permalink
core/vm: EXTCODE* return delegation designator for 7702
Browse files Browse the repository at this point in the history
ethereum/go-ethereum#31089

----
relates: kaiachain@5eeb56c
* core/vm: return delegation designator prefix for code reading ops
* ethereum/go-ethereum@fdfc159
  • Loading branch information
tnasu committed Jan 31, 2025
1 parent 89d0147 commit d7d68fe
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
6 changes: 0 additions & 6 deletions blockchain/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,6 @@ func ChangeGasCostForTest(jt *JumpTable, opCode OpCode, constantGas uint64) {

// 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
Expand Down
55 changes: 0 additions & 55 deletions blockchain/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"github.com/holiman/uint256"
"github.com/kaiachain/kaia/blockchain/types"
"github.com/kaiachain/kaia/common"
"github.com/kaiachain/kaia/common/math"
"github.com/kaiachain/kaia/crypto"
"github.com/kaiachain/kaia/crypto/sha3"
"github.com/kaiachain/kaia/params"
)
Expand Down Expand Up @@ -348,17 +346,6 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
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
}

func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
slot := scope.Stack.peek()
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
Expand Down Expand Up @@ -388,29 +375,6 @@ func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
return nil, nil
}

// 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
}

func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
var (
stack = scope.Stack
Expand All @@ -430,25 +394,6 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
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
}

// opExtCodeHash returns the code hash of a specified account.
// There are several cases when the function is called, while we can relay everything
// to `state.GetCodeHash` function to ensure the correctness.
Expand Down

0 comments on commit d7d68fe

Please sign in to comment.