The LevelOne and LevelTwo contracts have significantly different storage layouts, with inconsistencies in variable declarations and ordering. Upon upgrading from LevelOne to LevelTwo via the UUPS pattern, these mismatches will cause severe storage collisions where variables in LevelTwo will unintentionally access or overwrite storage slots previously used by different variables in LevelOne, leading to data corruption and critical system failures.
In Solidity, storage variables are assigned slots sequentially in the order they're declared. When using upgradeable contract patterns like UUPS, the proxy contract's storage layout must be preserved across implementations to maintain data integrity. Any mismatch in variable declarations between implementation versions will cause storage collisions.
Missing Variable in LevelTwo: LevelOne has uint256 schoolFees in slot 2, which is completely missing in LevelTwo, causing a cascading collision for all subsequent variables.
Missing Private Mappings: LevelOne's reviewCount and lastReviewTime mappings (slots 9 and 10) are missing in LevelTwo, further exacerbating the misalignment.
Array Position Shifts: The dynamic arrays listOfStudents and listOfTeachers have shifted from slots 11 and 12 in LevelOne to slots 8 and 9 in LevelTwo.
IERC20 Storage Shift: The usdc variable has shifted from slot 13 to slot 10.
When the proxy contract upgrades from LevelOne to LevelTwo:
Data Corruption Chain Reaction:
LevelTwo's sessionEnd will read/write to slot 2, which contained schoolFees in LevelOne
Every subsequent variable will read/write to incorrect slots, creating a cascading failure
Mapping Collision Examples:
LevelTwo's isTeacher will map to slot 5 but access data from slot 6 (LevelOne's isTeacher)
LevelTwo's studentScore will map to slot 7 but access data from slot 8 (LevelOne's studentScore)
Dynamic Array Corruption:
Arrays in Solidity store their length at the declared slot and data at keccak256(slot)
After upgrade, listOfStudents will read length from slot 8 (previously slot 11), likely yielding incorrect data
This could potentially expose or corrupt the data previously stored in slot 8 (LevelOne's studentScore)
Deep Storage Implications:
Mappings and arrays use sophisticated storage patterns that will be severely corrupted
For example, data at keccak256(slot) + key for mappings will be accessing entirely wrong sections of storage
Complete System Failure: The storage collisions will render LevelTwo's functionality completely broken upon upgrade, as every state variable will access incorrect data.
Financial Loss: Given that this contract deals with:
School fees (schoolFees)
Treasury funds (bursary)
Payment calculations (TEACHER_WAGE, PRINCIPAL_WAGE) The storage collisions will cause financial calculations to use incorrect data, potentially leading to financial losses.
Student Record Corruption:
Student status (isStudent)
Academic scores (studentScore)
Course completion status and review history will all be corrupted
Irreversible Data Loss: Since the upgrade process doesn't preserve data properly, critical information may be permanently lost or corrupted in the transition.
Identity Confusion: Teacher and student identities will be mixed up, potentially giving unauthorized access to teacher-only functions to students and vice versa.
The issue spans both contracts' entire storage layout:
In LevelOne:
In LevelTwo:
Match Storage Layout Exactly: Ensure LevelTwo declares all variables from LevelOne in the exact same order, even if some aren't used in LevelTwo's logic:
Use Storage Gaps: Implement storage gaps in both contracts to accommodate future additions without disrupting the layout:
Follow OpenZeppelin's Storage Upgrade Pattern: Use the structured approach to storage management from OpenZeppelin's upgradeable contracts library.
Implement Storage Layouts Diagram: Maintain a diagram or documentation showing the exact storage layout of both contracts to prevent accidental mismatches in future upgrades.
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.