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

Amend EIP-3860 per EIPs/pull/6249 #6502

Merged
merged 7 commits into from
Jan 6, 2023
Merged
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
1 change: 0 additions & 1 deletion core/vm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var (
ErrInsufficientBalance = errors.New("insufficient balance for transfer")
ErrContractAddressCollision = errors.New("contract address collision")
ErrExecutionReverted = errors.New("execution reverted")
ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded")
ErrMaxCodeSizeExceeded = errors.New("max code size exceeded")
ErrInvalidJump = errors.New("invalid jump destination")
ErrWriteProtection = errors.New("write protection")
Expand Down
4 changes: 0 additions & 4 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if !evm.context.CanTransfer(evm.intraBlockState, caller.Address(), value) {
return nil, common.Address{}, gas, ErrInsufficientBalance
}
// Check whether the init code size has been exceeded.
if evm.config.HasEip3860(evm.chainRules) && len(codeAndHash.code) > params.MaxInitCodeSize {
return nil, address, gas, ErrMaxInitCodeSizeExceeded
}
if incrementNonce {
nonce := evm.intraBlockState.GetNonce(caller.Address())
if nonce+1 < nonce {
Expand Down
30 changes: 10 additions & 20 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,15 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *stack.Stack, mem *Mem
return 0, err
}
len, overflow := stack.Back(2).Uint64WithOverflow()
if overflow {
if overflow || len > params.MaxInitCodeSize {
return 0, ErrGasUintOverflow
}
if len <= params.MaxInitCodeSize {
numWords := ToWordSize(len)
wordGas, overflow := math.SafeMul(numWords, params.InitCodeWordGas)
if overflow {
return 0, ErrGasUintOverflow
}
gas, overflow = math.SafeAdd(gas, wordGas)
if overflow {
return 0, ErrGasUintOverflow
}
numWords := ToWordSize(len)
// Since size <= params.MaxInitCodeSize, this multiplication cannot overflow
wordGas := params.InitCodeWordGas * numWords
gas, overflow = math.SafeAdd(gas, wordGas)
if overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
}
Expand All @@ -336,18 +332,12 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *stack.Stack, mem *Me
return 0, err
}
len, overflow := stack.Back(2).Uint64WithOverflow()
if overflow {
if overflow || len > params.MaxInitCodeSize {
return 0, ErrGasUintOverflow
}
wordCost := params.Keccak256WordGas
if len <= params.MaxInitCodeSize {
wordCost += params.InitCodeWordGas
}
numWords := ToWordSize(len)
wordGas, overflow := math.SafeMul(numWords, wordCost)
if overflow {
return 0, ErrGasUintOverflow
}
// Since size <= params.MaxInitCodeSize, this multiplication cannot overflow
wordGas := (params.InitCodeWordGas + params.Keccak256WordGas) * numWords
gas, overflow = math.SafeAdd(gas, wordGas)
if overflow {
return 0, ErrGasUintOverflow
Expand Down
3 changes: 3 additions & 0 deletions tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func TestBlockchain(t *testing.T) {
// For speedier CI-runs those are skipped.
bt.skipLoad(`^GeneralStateTests/`)

// Skipping due to https://github.com/ethereum/tests/issues/1133
bt.skipLoad(`^EIPTests/bc4895-withdrawals/`)

// Currently it fails because SpawnStageHeaders doesn't accept any PoW blocks after PoS transition
// TODO(yperbasis): make it work
bt.skipLoad(`^TransitionTests/bcArrowGlacierToMerge/powToPosBlockRejection\.json`)
Expand Down
18 changes: 18 additions & 0 deletions tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ var Forks = map[string]*params.ChainConfig{
TerminalTotalDifficultyPassed: true,
ShanghaiTime: big.NewInt(0),
},
"MergeToShanghaiAtTime15k": {
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
TangerineWhistleBlock: big.NewInt(0),
SpuriousDragonBlock: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
ShanghaiTime: big.NewInt(15_000),
},
}

// Returns the set of defined fork names
Expand Down
2 changes: 1 addition & 1 deletion tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestState(t *testing.T) {
st := new(testMatcher)

// EOF is not implemented yet
st.skipLoad(`^stEIP3540/`)
st.skipLoad(`^EIPTests/stEOF/`)

// Very time consuming
st.skipLoad(`^stTimeConsuming/`)
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata
Submodule testdata updated 131 files