The storage slots of the flash loan fee and the fee precision have switched storage slots between Thunderloan and ThunderLoanUpgraded. This leads to the values being read and written to storage incorrectly.
The storage layout is stored in the proxy contract and cannot be changed once the proxy has been deployed. When the implementation is upgraded from ThunderLoan to ThunderLoanUpgraded, the storage variables need to map to the correct, initially set, storage slots or there is a mismatch between the storage layout and the storage variables.
In the ThunderLoan contract on line 96-97, the storage slots of the fee precision (s_feePrecisison) and the flash loan fee (s_flashLoanFee) are declared in storage:
Whereas, in the ThunderLoanUpgraded contract, on line 96-97, the storage variables are stated in the reverse:
These variables are now pointing to the reverse storage slots. Hence, when FEE_PRECISION is modified or read, the flash loan fee storage is what is modified or read, and visa versa.
Since the flash loan fee and fee precision are now pointing to the incorrect storage slots, calculations will be performed incorrectly.
For fee precision, the initial value will be 3e15 rather than 1e18
Together this results in a fee that is much larger than expected. This is because the fee is calculated using the following function:
This reduces into the following calculation:
Hence, if the flash loan fee is larger than expected, and the fee precision is smaller than expected, the value of fee will increase.
This means that flash loans will be more expensive initially than desired.
Storage slots being incorrectly ordered have downstream impacts and is a high-severity vulnerability
The following test proves that when the implementation contract is upgraded from ThunderLoan to ThunderLoanUpgraded, getFee() returns a flash loan fee with the value intended for the fee precision:
The test passes, showing that the initial flash loan fee, s_flashLoanFee is 1e18 rather than 3e15 as desired. Hence, the storage variables are pointing to the incorrect storage slots.
Re-order the storage variable declarations in ThuderLoanUpgraded:
Forge
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.