mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +00:00
Co-authored-by: Martin HS <martin@swende.se>
This commit is contained in:
parent
b896f4dce1
commit
47abf2eb16
6 changed files with 21 additions and 9 deletions
|
|
@ -31,6 +31,7 @@ var (
|
||||||
ErrContractAddressCollision = errors.New("contract address collision")
|
ErrContractAddressCollision = errors.New("contract address collision")
|
||||||
ErrExecutionReverted = errors.New("execution reverted")
|
ErrExecutionReverted = errors.New("execution reverted")
|
||||||
ErrMaxCodeSizeExceeded = errors.New("max code size exceeded")
|
ErrMaxCodeSizeExceeded = errors.New("max code size exceeded")
|
||||||
|
ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded")
|
||||||
ErrInvalidJump = errors.New("invalid jump destination")
|
ErrInvalidJump = errors.New("invalid jump destination")
|
||||||
ErrWriteProtection = errors.New("write protection")
|
ErrWriteProtection = errors.New("write protection")
|
||||||
ErrReturnDataOutOfBounds = errors.New("return data out of bounds")
|
ErrReturnDataOutOfBounds = errors.New("return data out of bounds")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
|
|
||||||
|
|
@ -308,9 +309,12 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
size, overflow := stack.Back(2).Uint64WithOverflow()
|
size, overflow := stack.Back(2).Uint64WithOverflow()
|
||||||
if overflow || size > params.MaxInitCodeSize {
|
if overflow {
|
||||||
return 0, ErrGasUintOverflow
|
return 0, ErrGasUintOverflow
|
||||||
}
|
}
|
||||||
|
if size > params.MaxInitCodeSize {
|
||||||
|
return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size)
|
||||||
|
}
|
||||||
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
||||||
moreGas := params.InitCodeWordGas * ((size + 31) / 32)
|
moreGas := params.InitCodeWordGas * ((size + 31) / 32)
|
||||||
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
|
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
|
||||||
|
|
@ -325,9 +329,12 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
size, overflow := stack.Back(2).Uint64WithOverflow()
|
size, overflow := stack.Back(2).Uint64WithOverflow()
|
||||||
if overflow || size > params.MaxInitCodeSize {
|
if overflow {
|
||||||
return 0, ErrGasUintOverflow
|
return 0, ErrGasUintOverflow
|
||||||
}
|
}
|
||||||
|
if size > params.MaxInitCodeSize {
|
||||||
|
return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size)
|
||||||
|
}
|
||||||
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
||||||
moreGas := (params.InitCodeWordGas + params.Keccak256WordGas) * ((size + 31) / 32)
|
moreGas := (params.InitCodeWordGas + params.Keccak256WordGas) * ((size + 31) / 32)
|
||||||
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
|
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,17 @@ package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ func TestEIP2200(t *testing.T) {
|
||||||
vmenv := NewEVM(vmctx, TxContext{}, statedb, nil, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
|
vmenv := NewEVM(vmctx, TxContext{}, statedb, nil, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
|
||||||
|
|
||||||
_, gas, err := vmenv.Call(AccountRef(common.Address{}), address, nil, tt.gaspool, new(big.Int))
|
_, gas, err := vmenv.Call(AccountRef(common.Address{}), address, nil, tt.gaspool, new(big.Int))
|
||||||
if err != tt.failure {
|
if !errors.Is(err, tt.failure) {
|
||||||
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.failure)
|
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.failure)
|
||||||
}
|
}
|
||||||
if used := tt.gaspool - gas; used != tt.used {
|
if used := tt.gaspool - gas; used != tt.used {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
|
@ -260,7 +261,10 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
|
||||||
var dynamicCost uint64
|
var dynamicCost uint64
|
||||||
dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
|
dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
|
||||||
cost += dynamicCost // for tracing
|
cost += dynamicCost // for tracing
|
||||||
if err != nil || !contract.UseGas(dynamicCost, in.evm.Config.Tracer, tracing.GasChangeIgnored) {
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
|
||||||
|
}
|
||||||
|
if !contract.UseGas(dynamicCost, in.evm.Config.Tracer, tracing.GasChangeIgnored) {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
"gas": "0x1a034",
|
"gas": "0x1a034",
|
||||||
"init": "0x36600060003760406103e8366000600060095af26001556103e8516002556104085160035500"
|
"init": "0x36600060003760406103e8366000600060095af26001556103e8516002556104085160035500"
|
||||||
},
|
},
|
||||||
"error": "out of gas",
|
"error": "out of gas: not enough gas for reentrancy sentry",
|
||||||
"traceAddress": [],
|
"traceAddress": [],
|
||||||
"subtraces": 1,
|
"subtraces": 1,
|
||||||
"transactionPosition": 117,
|
"transactionPosition": 117,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
"gas": "0x19ee4",
|
"gas": "0x19ee4",
|
||||||
"init": "0x5a600055600060006000f0505a60015500"
|
"init": "0x5a600055600060006000f0505a60015500"
|
||||||
},
|
},
|
||||||
"error": "out of gas",
|
"error": "out of gas: not enough gas for reentrancy sentry",
|
||||||
"traceAddress": [],
|
"traceAddress": [],
|
||||||
"subtraces": 1,
|
"subtraces": 1,
|
||||||
"transactionPosition": 63,
|
"transactionPosition": 63,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue