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 1 commit 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
26 changes: 22 additions & 4 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,15 @@

func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
slot := scope.Stack.Peek()
codeSize, err := interpreter.evm.IntraBlockState().ResolveCodeSize(slot.Bytes20())

codeSize, err := interpreter.evm.IntraBlockState().GetCodeSize(slot.Bytes20())
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if codeSize == types.DelegateDesignationCodeSize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size check is not enough. The prefix of the code should be checked as well (see ParseDelegation).

codeSize = 2 // first two bytes only: EIP-7702
}

slot.SetUint64(uint64(codeSize))
return nil, nil
}
Expand Down Expand Up @@ -416,10 +421,17 @@
addr := libcommon.Address(a.Bytes20())
len64 := length.Uint64()

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

Check failure on line 432 in core/vm/instructions.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
}

codeCopy := getDataBig(code, &codeOffset, len64)
scope.Memory.Set(memOffset.Uint64(), len64, codeCopy)
return nil, nil
Expand Down Expand Up @@ -473,9 +485,15 @@
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)

Check failure on line 496 in core/vm/instructions.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
}
slot.SetBytes(codeHash.Bytes())
}
Expand Down
1 change: 1 addition & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const (
)

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