From 2207ab3c937adf08d81b1c01f38f0e246bf72e0e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 16 Mar 2023 08:53:52 -0700 Subject: [PATCH] fix: eth: handle a potential divide by zero in receipt handling This isn't really possible to hit on-chain at this piont (message won't be accepted) but we might as well be extra careful. fixes #10471 --- node/impl/full/eth.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 26fed34b0..14812e4de 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -2165,7 +2165,10 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook gasOutputs := vm.ComputeGasOutputs(lookup.Receipt.GasUsed, int64(tx.Gas), baseFee, big.Int(tx.MaxFeePerGas), big.Int(tx.MaxPriorityFeePerGas), true) totalSpent := big.Sum(gasOutputs.BaseFeeBurn, gasOutputs.MinerTip, gasOutputs.OverEstimationBurn) - effectiveGasPrice := big.Div(totalSpent, big.NewInt(lookup.Receipt.GasUsed)) + effectiveGasPrice := big.Zero() + if lookup.Receipt.GasUsed > 0 { + effectiveGasPrice = big.Div(totalSpent, big.NewInt(lookup.Receipt.GasUsed)) + } receipt.EffectiveGasPrice = ethtypes.EthBigInt(effectiveGasPrice) if receipt.To == nil && lookup.Receipt.ExitCode.IsSuccess() {