You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspect and verify the behavior of RefundGas with its own tests.
It should not be possible to refund negative gas
RefundGas with 0 should be a no-op
Warning Generated by Coderabbit
[Click to Expand]
Prevent negative gas refund calculation
The calculation msg.Gas() - evmResp.GasUsed could result in a negative value if evmResp.GasUsed exceeds msg.Gas(). This could lead to unintended behavior or panic due to negative gas values.
Consider ensuring the refund amount is non-negative:
+refundGas := msg.Gas() - evmResp.GasUsed+if refundGas < 0 {+ refundGas = 0+}
if err = k.RefundGas(ctx, msg, refundGas, evmConfig.Params.EvmDenom); err != nil {
return nil, errors.Wrapf(err, "failed to refund leftover gas to sender %s", msg.From())
}
📝 Committable suggestion
‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
refundGas := msg.Gas() - evmResp.GasUsed
if refundGas < 0 {
refundGas = 0
}
if err = k.RefundGas(ctx, msg, refundGas, evmConfig.Params.EvmDenom); err != nil {
return nil, errors.Wrapf(err, "failed to refund leftover gas to sender %s", msg.From())
}
The Ask
Deadline: 2024-10-15
Warning Generated by Coderabbit
[Click to Expand]
Prevent negative gas refund calculation
The calculation
msg.Gas() - evmResp.GasUsed
could result in a negative value ifevmResp.GasUsed
exceedsmsg.Gas()
. This could lead to unintended behavior or panic due to negative gas values.Consider ensuring the refund amount is non-negative:
📝 Committable suggestion
Originally posted by @coderabbitai[bot] in #2053 (comment)
The text was updated successfully, but these errors were encountered: