The mintActiveStalk function is responsible for minting Stalk and Roots to a user's account. The calculation of Roots involves division operations, which are susceptible to rounding errors due to Solidity's integer division behavior. These rounding errors can lead to slight inaccuracies in user balances, which may accumulate over time and affect the overall system integrity.
The root cause of this issue is the use of integer division in Solidity, which always rounds down to the nearest integer. This can be observed in the mintActiveStalk function where the calculation of Roots involves division operations.
1: initial state:
s.sys.silo.stalk = 1000
s.sys.silo.roots = 4999
User has 100 stalk
Minting 123 stalk
2: Calculation:
3: Result:
Expected Roots: 614.877 (accurate calculation)
Actual Roots: 614 (due to rounding down)
Test Case 1: Small Values
Test Case 2: Large Values
1: Users' balances of Stalk and Roots will not accurately reflect their true value, leading to discrepancies.
2: Over time, the accumulation of rounding errors can affect the total supply calculations and the overall balance within the system.
3: Inaccurate balances can lead to user mistrust in the platform, potentially resulting in reduced user engagement and participation.
Manual review
1: Scaling Up Before Division
2: Using Fixed-Point Arithmetic
Implementing a fixed-point arithmetic library to handle fractional values can ensure precision is maintained:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.