Skip to content
Closed
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
5 changes: 5 additions & 0 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var activators = map[int]func(*JumpTable){
2200: enable2200,
1884: enable1884,
1344: enable1344,
3541: enable3541,
}

// EnableEIP enables the given EIP on the config.
Expand Down Expand Up @@ -144,3 +145,7 @@ func enable2929(jt *JumpTable) {
jt[SELFDESTRUCT].constantGas = params.SelfdestructGasEIP150
jt[SELFDESTRUCT].dynamicGas = gasSelfdestructEIP2929
}

func enable3541(jt *JumpTable) {
// Do nothing.
}
1 change: 1 addition & 0 deletions core/vm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
ErrWriteProtection = errors.New("write protection")
ErrReturnDataOutOfBounds = errors.New("return data out of bounds")
ErrGasUintOverflow = errors.New("gas uint64 overflow")
ErrInvalidCode = errors.New("invalid code")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Slightly unrelated question (not blocking this PR): EVMC has a CONTRACT_VALIDATION_FAILED error code (used as part of Ewasm 1.0). Probably we could use that error code for EOF1 validation, but should we use it already for this use case, or it makes more sense separating the error codes?

)

// ErrStackUnderflow wraps an evm error when the items on the stack less
Expand Down
14 changes: 14 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ func (c *codeAndHash) Hash() common.Hash {
return c.hash
}

func hasEIP3541(vmConfig *Config) bool {
for _, eip := range vmConfig.ExtraEips {
if eip == 3541 {
return true
}
}
return false
}

// create creates a new contract using code as deployment code.
func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *big.Int, address common.Address) ([]byte, common.Address, uint64, error) {
// Depth check execution. Fail if we're trying to execute above the
Expand Down Expand Up @@ -468,6 +477,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
err = ErrMaxCodeSizeExceeded
}

// Reject code starting with 0xEF if EIP-3541 is enabled.
if err == nil && len(ret) >= 1 && ret[0] == 0xEF && hasEIP3541(&evm.vmConfig) {
err = ErrInvalidCode
}

// if the contract creation ran successfully and no errors were returned
// calculate the gas required to store the code. If the code could not
// be stored due to not enough gas set an error and let it be handled
Expand Down