BriVault

First Flight #52
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

Stale Registered Shares After Cancellation Inflates Winner Denominator

Title: Stale Registered Shares After Cancellation Inflates Winner Denominator

  • Impact: When a participant cancels, their on‑chain registered share mapping (userSharesToCountry) is not cleared. Later, computing totalWinnerShares sums stale entries and reduces winners’ payouts.

  • Evidence: cancelParticipation burns tokens and refunds principal but does not clear mapping entries used by _getWinnerShares.

  • Recommendation (formal mitigation):

    1. On cancelParticipation, zero-out or delete userSharesToCountry[msg.sender][registeredCountryId] and remove userToCountry and userCountryId mappings.

    2. Remove the participant from usersAddress using a swap-and-pop pattern and clear hasJoined flag to prevent duplicate counting.

    3. Add unit tests validating _getWinnerShares before and after cancellations.

Illustrative fix:

uint256 registeredCountryId = userCountryId[msg.sender];
delete userSharesToCountry[msg.sender][registeredCountryId];
delete userToCountry[msg.sender];
delete userCountryId[msg.sender];
_removeParticipant(msg.sender); // implements swap-and-pop and clears hasJoined flag

Medium Finding (F-004)

Title: deposit() Overwrites stakedAsset Instead of Accumulating

  • Impact: Multiple deposits by the same user overwrite stakedAsset[receiver], under‑reporting refundable principal on cancel and causing loss of funds.

  • Evidence: stakedAsset[receiver] = stakeAsset; used instead of additive update.

  • Recommendation (formal mitigation):

    1. Use cumulative accounting: stakedAsset[receiver] += stakeAsset; and ensure userSharesToCountry is also incremented cumulatively.

    2. Add unit tests for multiple deposits and ensure cancelParticipation refunds the sum of deposits proportional to burned shares.

Minimal fix:

stakedAsset[receiver] += stakeAsset;
userSharesToCountry[receiver][countryId] += shares;

Updates

Appeal created

bube Lead Judge 19 days ago
Submission Judgement Published
Validated
Assigned finding tags:

`cancelParticipation` Leaves Stale Winner Data

CancelParticipation burns shares but leaves the address inside usersAddress and keeps userSharesToCountry populated.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!