Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Make RefundGas safer (potential issue) #2059

Open
3 tasks
Unique-Divine opened this issue Oct 2, 2024 · 0 comments
Open
3 tasks

[bug] Make RefundGas safer (potential issue) #2059

Unique-Divine opened this issue Oct 2, 2024 · 0 comments

Comments

@Unique-Divine
Copy link
Member

Unique-Divine commented Oct 2, 2024

The Ask

Deadline: 2024-10-15

  • 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())
	}

Originally posted by @coderabbitai[bot] in #2053 (comment)

@github-actions github-actions bot added the S-triage Status: This issue is waiting on initial triage. More Info: https://tinyurl.com/25uty9w5 label Oct 2, 2024
@Unique-Divine Unique-Divine removed the S-triage Status: This issue is waiting on initial triage. More Info: https://tinyurl.com/25uty9w5 label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ⚡ Building 🧱
Development

No branches or pull requests

1 participant