Skip to content

Commit

Permalink
Add gas payment to PAYGAS, return error if balance insufficient
Browse files Browse the repository at this point in the history
  • Loading branch information
adietrichs committed Jun 3, 2020
1 parent b4d1e84 commit f89c7ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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")
ErrPaygasInsufficientFunds = errors.New("insufficient funds for gas * price + value")
)

// ErrStackUnderflow wraps an evm error when the items on the stack less
Expand Down
7 changes: 6 additions & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f89c7ea

Please sign in to comment.