MyCut

AI First Flight #8
Beginner FriendlyFoundry
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

`ContestManager::createContest` stores `totalRewards` redundantly (also held in Pot) — inefficient, dual source of truth

Description


ContestManager::createContestis implemented inefficiently. It redundantly stores totalRewardsin the contestToTotalRewardsmapping even though the Potitself already stores the same value (i_totalRewards, exposed via the pot). This duplicate SSTORE wastes gas on every contest creation, and the mapping must be kept in sync with the pot.


function createContest(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards)
public onlyOwner returns (address)
{
Pot pot = new Pot(players, rewards, token, totalRewards);
contests.push(address(pot));
contestToTotalRewards[address(pot)] = totalRewards; // @> redundant: Pot already stores totalRewards
return address(pot);
}
```
​
Additionally, `fundContest` re-reads `totalRewards` from the mapping and `getToken()` from the pot across separate external calls, where the data could be sourced more directly.
​
## Risk
​
**Likelihood: Low**
​
- Pure gas-efficiency / code-quality issue; it executes on every `createContest` but has no safety impact.
​
**Impact: Low**
​
- Unnecessary storage writes and reads increase gas costs and introduce a second source of truth (`contestToTotalRewards`) that can drift from the pot's own value. No loss of funds; efficiency and maintainability only.
​
## Proof of Concept
​
```solidity
// Every createContest performs an extra SSTORE of totalRewards into contestToTotalRewards,
// duplicating the value already held in the Pot (i_totalRewards).
```
​
## Recommended Mitigation
​
Drop the redundant mapping and read `totalRewards` from the pot when needed (add a getter on `Pot`), or only keep whichever single source of truth is actually required:
​
```solidity
// remove contestToTotalRewards; expose Pot.getTotalRewards() and read it where needed.
```
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 hours ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!