-
Notifications
You must be signed in to change notification settings - Fork 228
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
fix: consider movevm gas scale factor #287
Conversation
📝 WalkthroughWalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (k Keeper) computeGasForRuntime(ctx context.Context, gasMeter storetypes.GasMeter) uint64 { | ||
gasForRuntime := gasMeter.Limit() - gasMeter.GasConsumedToLimit() | ||
if isSimulation(ctx) { | ||
gasForRuntime = k.config.ContractSimulationGasLimit | ||
} | ||
|
||
// gasUnitScale is multiplied in moveVM to scale the gas limit, so we need to divide it here | ||
// if gasForRuntime is too large, it will overflow when multiplied in moveVM. | ||
const gasUintScale = 100 | ||
if gasForRuntime > math.MaxUint64/gasUintScale { | ||
return math.MaxUint64 / gasUintScale | ||
} | ||
|
||
return gasForRuntime | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add unit tests for 'computeGasForRuntime' function
The new function computeGasForRuntime
handles critical logic for gas limit calculations and includes an overflow check. To ensure its correctness and prevent future regressions, it would be beneficial to add unit tests that cover:
- Standard scenarios with various gas meter limits and consumed gas
- Simulation mode where
isSimulation(ctx)
returnstrue
- Cases where the overflow check is triggered due to high
gasForRuntime
values
// gasUnitScale is multiplied in moveVM to scale the gas limit, so we need to divide it here | ||
// if gasForRuntime is too large, it will overflow when multiplied in moveVM. | ||
const gasUintScale = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the variable name 'gasUintScale' to 'gasUnitScale' to match comments
There is a spelling inconsistency between the variable name gasUintScale
and the comments, which refer to gasUnitScale
. To maintain consistency and improve code readability, consider renaming gasUintScale
to gasUnitScale
.
Apply this diff to correct the variable name:
-const gasUintScale = 100
+const gasUnitScale = 100
Ensure all references to gasUintScale
are updated accordingly.
📝 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.
// gasUnitScale is multiplied in moveVM to scale the gas limit, so we need to divide it here | |
// if gasForRuntime is too large, it will overflow when multiplied in moveVM. | |
const gasUintScale = 100 | |
// gasUnitScale is multiplied in moveVM to scale the gas limit, so we need to divide it here | |
// if gasForRuntime is too large, it will overflow when multiplied in moveVM. | |
const gasUnitScale = 100 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #287 +/- ##
==========================================
+ Coverage 40.64% 40.67% +0.02%
==========================================
Files 267 267
Lines 25415 25423 +8
==========================================
+ Hits 10331 10341 +10
+ Misses 13499 13498 -1
+ Partials 1585 1584 -1
|
* support multisend * bump movevm to v0.5.1 * add missing stargate query support (#285) * fix nil memory access on authz (#281) * fix: allow to be failed with invalid message without error (#283) * allow to failed with invalid message * set reason * fix to consider movevm gas scale when we use infinity gas meter (#287) * fix to use cache context at ibc hook (#288) * feat: enable whitelist stableswap (#289) * enable whitelist stableswap * check division by zero and handle default values for balancer * remove unnecessary slices.Copy * ignore error * fix test * apply coderabbit comment * emit same events with cosmos-sdk interface * create account if not exists
Description
When we pass gas balance to movevm, then movevm will multiply it by scaleFactor (100) to scale it up to movevm unit. To avoid overflow in this process, we need to divide gasForRuntime when we use infinity gas meter.
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...