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

[Do-Not-Merge] Implement EXTCODE* changes for pdn-5 #13106

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
18 changes: 0 additions & 18 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,6 @@ func (sdb *IntraBlockState) ResolveCode(addr libcommon.Address) ([]byte, error)
return sdb.GetCode(addr)
}

func (sdb *IntraBlockState) ResolveCodeSize(addr libcommon.Address) (int, error) {
// eip-7702
size, err := sdb.GetCodeSize(addr)
if err != nil {
return 0, err
}
if size == types.DelegateDesignationCodeSize {
// might be delegated designation
code, err := sdb.ResolveCode(addr)
if err != nil {
return 0, err
}
return len(code), nil
}

return size, nil
}

func (sdb *IntraBlockState) GetDelegatedDesignation(addr libcommon.Address) (libcommon.Address, bool, error) {
// eip-7702
code, err := sdb.GetCode(addr)
Expand Down
1 change: 0 additions & 1 deletion core/vm/evmtypes/evmtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ type IntraBlockState interface {
// eip-7702; delegated designations
ResolveCodeHash(common.Address) (common.Hash, error)
ResolveCode(common.Address) ([]byte, error)
ResolveCodeSize(common.Address) (int, error)
GetDelegatedDesignation(common.Address) (common.Address, bool, error)

AddRefund(uint64)
Expand Down
31 changes: 27 additions & 4 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,20 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte

func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
slot := scope.Stack.Peek()
codeSize, err := interpreter.evm.IntraBlockState().ResolveCodeSize(slot.Bytes20())
addr := slot.Bytes20()
codeSize, err := interpreter.evm.IntraBlockState().GetCodeSize(addr)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if codeSize == types.DelegateDesignationCodeSize {
_, ok, err := interpreter.evm.IntraBlockState().GetDelegatedDesignation(addr)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if ok {
codeSize = 2 // first two bytes only: EIP-7702
}
}
slot.SetUint64(uint64(codeSize))
return nil, nil
}
Expand Down Expand Up @@ -416,10 +426,14 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
addr := libcommon.Address(a.Bytes20())
len64 := length.Uint64()

code, err := interpreter.evm.IntraBlockState().ResolveCode(addr)
code, err := interpreter.evm.IntraBlockState().GetCode(addr)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if _, ok := types.ParseDelegation(code); ok {
code = append([]byte{}, (params.DelegatedDesignationPrefix[0:2])...)
}

codeCopy := getDataBig(code, &codeOffset, len64)
scope.Memory.Set(memOffset.Uint64(), len64, codeCopy)
return nil, nil
Expand Down Expand Up @@ -473,9 +487,18 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
if empty {
slot.Clear()
} else {
codeHash, err := interpreter.evm.IntraBlockState().ResolveCodeHash(address)
var codeHash libcommon.Hash
_, ok, err := interpreter.evm.IntraBlockState().GetDelegatedDesignation(address)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if ok {
codeHash = params.DelegatedCodeHash
} else {
codeHash, err = interpreter.evm.IntraBlockState().GetCodeHash(address)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
}
slot.SetBytes(codeHash.Bytes())
}
Expand Down
2 changes: 2 additions & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ const (
SetCodeMagicPrefix = byte(0x05)
)

// EIP-7702: Set EOA account code
var DelegatedDesignationPrefix = []byte{0xef, 0x01, 0x00}
var DelegatedCodeHash = common.HexToHash("0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329")

// EIP-4788: Beacon block root in the EVM
var BeaconRootsAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")
Expand Down
Loading