mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/vm: better error-info for vm errors
This commit is contained in:
parent
58a3e2f180
commit
43ab2d2501
3 changed files with 10 additions and 2 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")
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package vm
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
|
@ -326,9 +327,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 {
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,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, err
|
||||||
|
}
|
||||||
|
if !contract.UseGas(dynamicCost, in.evm.Config.Tracer, tracing.GasChangeIgnored) {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue