Skip to content

Commit 8137ddf

Browse files
cleanup the overflow check
1 parent af57baa commit 8137ddf

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

fvm/evm/handler/handler.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,12 @@ func (h *ContractHandler) BatchRun(rlpEncodedTxs [][]byte, gasFeeCollector types
204204
}
205205

206206
func (h *ContractHandler) batchRun(rlpEncodedTxs [][]byte) ([]*types.Result, error) {
207-
// step 1 - transaction decoding and compute total gas needed
208-
// This is safe to be done before checking the gas
209-
// as it has its own metering
210-
var totalGas types.GasLimit
211-
gasLimit := h.backend.ComputationRemaining(environment.ComputationKindEVMGasUsage)
207+
// step 1 - transaction decoding and check that enough evm gas is available in the FVM transaction
208+
209+
// remainingGasLimit is the remaining EVM gas available in hte FVM transaction
210+
remainingGasLimit := h.backend.ComputationRemaining(environment.ComputationKindEVMGasUsage)
212211
batchLen := len(rlpEncodedTxs)
213212
txs := make([]*gethTypes.Transaction, batchLen)
214-
215213
for i, rlpEncodedTx := range rlpEncodedTxs {
216214
tx, err := h.decodeTransaction(rlpEncodedTx)
217215
// if any tx fails decoding revert the batch
@@ -221,15 +219,12 @@ func (h *ContractHandler) batchRun(rlpEncodedTxs [][]byte) ([]*types.Result, err
221219

222220
txs[i] = tx
223221

224-
// overflow protection
225-
if totalGas+types.GasLimit(tx.Gas()) < totalGas {
226-
return nil, types.ErrInsufficientComputation
227-
}
228222
// step 2 - check if enough computation is available
229-
totalGas += types.GasLimit(tx.Gas())
230-
if uint64(totalGas) > gasLimit {
223+
txGasLimit := tx.Gas()
224+
if remainingGasLimit < txGasLimit {
231225
return nil, types.ErrInsufficientComputation
232226
}
227+
remainingGasLimit -= txGasLimit
233228
}
234229

235230
// step 3 - prepare block context

0 commit comments

Comments
 (0)