fix: prevent reward dilution via zero sharesReward harvest#808
fix: prevent reward dilution via zero sharesReward harvest#808Ishant5436 wants to merge 3 commits into
Conversation
|
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
Warning Review limit reached
More reviews will be available in 25 minutes and 45 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIn Changesharvest() zero-reward notification guard
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
contracts/StakedEXA.sol (1)
352-356:⚠️ Potential issue | 🟠 Major | ⚡ Quick winEarly return drops the “send remainder to savings” path when reward rounds to zero.
With the new guard,
harvest()exits beforesaveis transferred. Ifshares > 0andsharesReward == 0(e.g.,providerRatio == 0or rounding), assets are no longer moved tosavings, which changes accounting/fund flow behavior.Suggested fix
function harvest() external whenNotPaused { Market memMarket = market; address memProvider = provider; uint256 shares = Math.min(memMarket.allowance(memProvider, address(this)), memMarket.maxRedeem(memProvider)); uint256 sharesReward = shares.mulWadDown(providerRatio); - if (sharesReward == 0) return; + if (shares == 0) return; + + uint256 save = shares - sharesReward; + if (save != 0) memMarket.transferFrom(memProvider, savings, save); + if (sharesReward == 0) return; memMarket.transferFrom(provider, address(this), sharesReward); - uint256 save = shares - sharesReward; - if (save != 0) memMarket.transferFrom(memProvider, savings, save); notifyRewardAmount(IERC20(address(memMarket)), sharesReward, address(this)); }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d9d6a2e3-676a-430b-bd34-c92160f45607
📒 Files selected for processing (1)
contracts/StakedEXA.sol
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 685d8746ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| address memProvider = provider; | ||
| uint256 shares = Math.min(memMarket.allowance(memProvider, address(this)), memMarket.maxRedeem(memProvider)); | ||
| uint256 sharesReward = shares.mulWadDown(providerRatio); | ||
| if (sharesReward == 0) return; |
There was a problem hiding this comment.
Do not skip savings transfer when reward share is zero
This return fires not only when there are no provider shares, but also when providerRatio is 0 or the reward portion rounds down to 0. setProviderRatio permits 0 and the harvest path documents that the non-rewarded portion goes to savings; with a zero ratio, shares can be the provider's full redeemable balance but the function exits before transferring save = shares - sharesReward, so deployments that route all provider funds to savings leave them in the provider indefinitely.
Useful? React with 👍 / 👎.
fix: prevent reward dilution via zero sharesReward harvest
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
|
I've applied the suggested fix! The early return was removed so |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
contracts/StakedEXA.sol (2)
347-358: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider adding early return when
sharesis zero.When both the allowance and
maxRedeemare zero,shareswill be zero, making bothsharesRewardandsavezero. The current implementation executes a zero-valuetransferFromat line 353, which wastes gas without accomplishing anything useful.⚡ Proposed gas optimization
function harvest() external whenNotPaused { Market memMarket = market; address memProvider = provider; uint256 shares = Math.min(memMarket.allowance(memProvider, address(this)), memMarket.maxRedeem(memProvider)); + if (shares == 0) return; uint256 sharesReward = shares.mulWadDown(providerRatio);
29-29:⚠️ Potential issue | 🟠 MajorUpdate Solidity pragma version to comply with coding guidelines.
The pragma is currently set to
^0.8.0but must be^0.8.17per the coding guidelines. Update line 2:pragma solidity ^0.8.17;Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b19124ec-195a-4a9d-babc-c7ac8fc89876
📒 Files selected for processing (1)
contracts/StakedEXA.sol
|
@coderabbitai I've updated the pragma to |
|
Tip For best results, initiate chat on the files or code changes.
I'm withdrawing the gas optimization suggestion accordingly. 🐇 ✨ ✏️ Learnings added
|
Summary
Fixes a vulnerability in
StakedEXA.solwhere callingharvest()with a zero allowance (or calculating to a zerosharesReward) would inadvertently callnotifyRewardAmount(0). This caused the reward rate to stretch out over the full duration, diluting the active rewards for stakers.Changes
contracts/StakedEXA.sol: Added an early returnif (sharesReward == 0)inharvest().Testing
notifyRewardAmount.pnpm testsuccessfully completed.Summary by CodeRabbit