diff --git a/core/vm/errors.go b/core/vm/errors.go index c813aa36af36..3004ca9093e4 100644 --- a/core/vm/errors.go +++ b/core/vm/errors.go @@ -34,6 +34,7 @@ var ( ErrWriteProtection = errors.New("write protection") ErrReturnDataOutOfBounds = errors.New("return data out of bounds") ErrGasUintOverflow = errors.New("gas uint64 overflow") + ErrPaygasInsufficientFunds = errors.New("insufficient funds for gas * price + value") ) // ErrStackUnderflow wraps an evm error when the items on the stack less diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 30fe5e3a4ce8..68656e179d30 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -907,7 +907,12 @@ func opPaygas(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([] if interpreter.paygasMode == PaygasNoOp { interpreter.intPool.put(gasprice) } else { - // TODO: Check the computed value against the GasPrice set in the tx + mgval := new(big.Int).Mul(new(big.Int).SetUint64(interpreter.evm.GasLimit), gasprice) + if interpreter.evm.StateDB.GetBalance(callContext.contract.Address()).Cmp(mgval) < 0 { + return nil, ErrPaygasInsufficientFunds + } + interpreter.evm.StateDB.SubBalance(callContext.contract.Address(), mgval) + interpreter.evm.snapshots[len(interpreter.evm.snapshots)-1] = interpreter.evm.StateDB.Snapshot() interpreter.paygasMode = PaygasNoOp interpreter.paygasPrice = gasprice