Description: The LevelOne contract's graduateAndUpgrade() function contains a severe vulnerability that can permanently prevent contract upgrades and payment distributions. The function includes an unbounded loop that iterates through all teachers to transfer tokens, with each transfer consuming significant gas. As the number of teachers grows, this will inevitably exceed block gas limits, rendering the function inoperable and permanently locking the contract in its current implementation.
Code Snippet:
Impact: This vulnerability creates a critical flaw in the contract's upgrade mechanism. Once the teacher count exceeds a certain threshold, the upgrade mechanism becomes permanently blocked due to gas limitations. This effectively:
Prevents all future contract upgrades, locking the system in its current implementation
Freezes all teacher and principal payments in the contract
Breaks a core contract feature that's essential for the school's operation and evolution
Detailed Analysis: Each ERC20 transfer operation in the loop requires:
Base transaction cost: ~21,000 gas
ERC20 transfer cost: ~20,000-50,000 gas (varies by token implementation)
With current Ethereum block gas limits (~30M), this function could handle approximately 600-1000 teachers in optimal conditions. However, the actual limit is likely lower due to other operations in the function and potential complexities in the token transfer implementation.
Proof of Concept:
A school system is deployed and operates successfully with 20 teachers.
Over time, the school grows to 800 teachers.
When the principal attempts to upgrade the contract, the transaction consistently fails due to out of gas errors.
The contract is now stuck in its current implementation, unable to upgrade.
Teacher and principal payments are permanently locked in the contract.
Recommended Mitigation: Implement a withdrawal pattern instead of pushing payments, alongside a batch processing system for upgrades:
Due to the use of a push system as regards payment of teacher wages, there is a risk of possible DoS as gas costs increase in direct proportion to size of teachers list.
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.