Skip to content

Commit

Permalink
safe gas add (ethereum#98)
Browse files Browse the repository at this point in the history
* safe gas add

* fix build
  • Loading branch information
gballet authored Apr 12, 2022
1 parent 298d8ce commit 439be0c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vm

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -410,8 +411,12 @@ func touchEachChunksOnReadAndChargeGas(offset, size uint64, address []byte, code
for i := offset / 31; i <= (endOffset-1)/31; i++ {
index := trieUtils.GetTreeKeyCodeChunk(address, uint256.NewInt(i))

// TODO safe-add here to catch overflow
statelessGasCharged += accesses.TouchAddressOnReadAndComputeGas(index)
var overflow bool
statelessGasCharged, overflow = math.SafeAdd(statelessGasCharged, accesses.TouchAddressOnReadAndComputeGas(index))
if overflow {
panic("overflow when adding gas")
}

if code != nil && len(code) > 0 {
if deployment {
accesses.SetLeafValue(index[:], nil)
Expand Down

0 comments on commit 439be0c

Please sign in to comment.