Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YBSNZfoCq2XqymbVV9r5rE
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #934 +/- ##
===============================================
- Coverage 96.56% 92.11% -4.46%
===============================================
Files 199 159 -40
Lines 67407 28774 -38633
===============================================
- Hits 65094 26506 -38588
+ Misses 2313 2268 -45 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes audit Finding 2 (Critical): "A distribution whose emission is smaller than its duration destroys the emission". This is the surviving failure mode of Oak Security's November 2024 finding 4.
Root cause
get_active_total_earned_puvpcomputed the rewards emitted since the last update asi.e. it floored to whole tokens before applying the 10^39 precision scale factor. Any update covering less than one full emission period (for example an
amountof 100 over 200 blocks, updated every block by ordinary membership or staking changes) contributed zero, and because the accumulator's clock is advanced unconditionally afterwards, that interval could never contribute again. The emission was destroyed, whileUndistributedRewardsstill reported it as distributed.Fix
Apply the scale factor before the floor, so truncation happens at the precision the accumulator actually carries:
The total credited over any sequence of updates is now within 10^-39 of
amount * elapsed / durationregardless of update frequency. Claims remain bounded by whatget_rewards_untilreports as distributed (whole-token floor of the same quantity), soWithdrawandUndistributedRewardscannot pay out more than was credited.Tests
test_small_linear_emission_survives_incremental_accumulator_updatesreproduces the audit scenario: 100 tokens over 200 blocks on a cw4 DAO, with the accumulator advanced once per block by membership changes that keep total voting power constant. It asserts the exact accumulator value after the first block and after 200 blocks, and that a member holding half the voting power can claim 50 tokens. It fails ondevelopment(accumulator stays at 0) and passes with the fix.Verified locally:
cargo test -p dao-rewards-distributor(67 passed),cargo +nightly-2024-01-08 fmt --all -- --check,cargo +nightly-2024-01-08 clippy --all-targets -- -D warnings.Not included (audit follow-ups)
🤖 Generated with Claude Code
https://claude.ai/code/session_01YBSNZfoCq2XqymbVV9r5rE