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

[audit] 2. Incorrect reward distribution due to inconsistent voting power queries #863

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

NoahSaso
Copy link
Member

@NoahSaso NoahSaso commented Aug 2, 2024

From Oak:

In contracts/distribution/dao-rewards-distributor/src/rewards.rs:113-136, the get_active_total_earned_puvp function computes the reward index by dividing the accrued rewards with total voting power queried from the previous block height (see contracts/distribution/dao-rewards-distributor/src/helpers.rs:19). This is incorrect because the user reward is computed with voting power queried from the current block height, as seen in contracts/distribution/dao-rewards-distributor/src/helpers.rs:33.

Consequently, the reward index will be computed using an outdated total voting power, resulting in incorrect reward distribution. An attacker can exploit this issue by staking many tokens one block before claiming the rewards to receive more at the expense of other users.

This fix ensures that the total voting power from the same height as the member's voting powers is used.

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.64%. Comparing base (2cac217) to head (b7b1ac3).

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #863   +/-   ##
============================================
  Coverage        96.64%   96.64%           
============================================
  Files              241      241           
  Lines            65432    65464   +32     
============================================
+ Hits             63234    63266   +32     
  Misses            2198     2198           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@bekauz bekauz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@NoahSaso NoahSaso merged commit ec3cec7 into development Aug 12, 2024
7 of 9 checks passed
@NoahSaso NoahSaso deleted the noah/rewards-audit-fix-2 branch August 12, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants