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] 5. Units of duration are not distinguished #871

Merged
merged 3 commits into from
Aug 11, 2024

Conversation

NoahSaso
Copy link
Member

@NoahSaso NoahSaso commented Aug 2, 2024

From Oak:

Time durations are crucial to the logic of the dao-rewards-distributor contract. However, the data types implemented are error-prone.

For example, the get_exp_diff function in contracts/distribution/dao-rewards-distributor/src/helpers.rs:78 subtracts one Expiration from another. Although the end and start parameters explicitly indicate the unit duration types (i.e., blocks or seconds), this information is not preserved in the output as the function returns u64 instead of the Expiration struct.

Additionally, the get_exp_diff function returns 0 if the input parameters are both Expiration::Never, which is mathematically incorrect.

Similarly, the get_duration_scalar function in line 42 removes the duration unit information and directly returns the inner value as u64, further elevating the potential for errors.

Consequently, the code responsible for managing distribution schedules and timeframes becomes more challenging to interpret, particularly when it involves arithmetic operations with mixed time units. This complexity increases the likelihood of bugs in these segments.

This fix improves names and adds traits to make the code more readable and expands upon the comments to help explain what the helper functions do.

The contract's logic ensures that start and end Expiration units always match the configured emission rate Duration units, so the errors in the helper functions should never be encountered.

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 12 lines in your changes missing coverage. Please review.

Project coverage is 96.64%. Comparing base (75272b9) to head (4a0768e).

Files Patch % Lines
...istribution/dao-rewards-distributor/src/helpers.rs 65.71% 12 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           development     #871      +/-   ##
===============================================
- Coverage        96.64%   96.64%   -0.01%     
===============================================
  Files              240      240              
  Lines            65294    65302       +8     
===============================================
+ Hits             63106    63108       +2     
- Misses            2188     2194       +6     

☔ 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.

lgtm!

@bekauz bekauz merged commit 116d320 into development Aug 11, 2024
6 of 9 checks passed
@bekauz bekauz deleted the noah/rewards-audit-fix-5 branch August 11, 2024 19:46
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