In the LevelOne.sol::graduateAndUpgrade function, the contract pays the teacher and principal wages using the bursary balance, but fails to update the bursary afterward. This results in incorrect funds remaining in the bursary, causing future wage calculations to overestimate available funds and violate accurate accounting principles.
The LevelOne.sol::graduateAndUpgrade function calculates the teacher and principal wages using the bursary balance.
However, the bursary value is not updated after the wage payments are made via external safeTransfer calls. As a result:
Incorrect bursary balance remains, causing subsequent to use outdated values.
Future wage payments will be overestimated.
The contract also violates the Check-Effects-Interactions pattern.
Not updating the internal state before making external calls can be dangerous as it can lead to unexpected behaviour and vulnerabilities.
Impacted code:
Impact: High – Incorrect bursary funds affect all future calculations and disbursements.
Likelihood: High – This function is expected to be called routinely during upgrades, consistently introducing accounting errors.
Manual review
Foundry test
Proof of Concept:
Adding the below code to the LeveOnelAndGraduateTest.t.sol file demonstrate that the bursary is unchanged after paying the teacher and principal wages:
1. Update the bursary before any external calls:
By adding the line bursary -= (totalTeacherPay + principalPay); before the wage payments, the bursary will be updated before any external calls and stay in line with the Checks-Effects-Interactions pattern.
Note: The above code has also been updated to reflect the correct calculation of the teacher wages as per my other finding related to this function.
The bursary is not updated after wages have been paid in `graduateAndUpgrade()` function
The bursary is not updated after wages have been paid in `graduateAndUpgrade()` function
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.