During the testing phase of the Pot smart contract, critical discrepancies were identified in the reward distribution among claimants and the contract owner. The root of these issues was traced to precision errors in mathematical calculations and inconsistent array referencing. Post-refactoring, these issues were resolved, confirming the presence of significant bugs in the original implementation. This detailed report outlines the identified vulnerabilities, provides a proof of concept (PoC) test case, and offers recommendations to prevent future occurrences of such vulnerabilities.
Issue: The function originally calculated managerCut
as remainingRewards / managerCutPercent
. This integer division could lead to significant truncation errors since Solidity does not handle fractional values.
Example: If remainingRewards
were 1,000 and managerCutPercent
were 11, the calculation 1000 / 11
would result in 90, discarding the fractional part entirely.
Issue: The for-loop iterated over claimants
while the calculation of claimantCut
used i_players.length
. This discrepancy could lead to an out-of-bounds error or fail to distribute rewards correctly if the lengths of claimants
and i_players
differed.
Severity: Medium
Impact: The truncation of fractional values during division leads to inaccurate reward distributions. Specifically, the owner (managerCut
) and players (claimantCut
) might receive less than their intended share, resulting in financial discrepancies.
Severity: Low to Medium
Impact: Using differing arrays for calculations and iteration can lead to mismatched reward distributions or potential out-of-bounds errors, causing incomplete or erroneous payouts to claimants.
Add PotTest.sol to the test folder:
Run: forge test --match-contract PotTest -vvv
Failure Details:
Foundry
Refactored closePot Function
Run ' forge test --match-contract PotTest -vvv' again.
You will now see it passing the test :
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.