State variables are not in the same storage memory slots.
After contract upgrade, both storage memory at index one and at index two will be overwritten with bad data.
In part, storage memory slots for the current ThunderLoan.sol
contract looks like this:
In part, storage memory slots for the planned ThunderLoanUpgraded.sol
contract looks like this:
When the proxy contract uses delegatecall
low level function, it will execute logic from one of these implementation contracts and update the storage memory of the proxy contract itself.
This means that (before the upgrade) when flash loan fee is updated (at some point), the proxy's storage slot at that specific location will be updated.
After the upgrade, fee precision is changed to a constant meaning that it will not be part of the contract storage memory any more as it was in previous contract version. That storage slot will now instead be associated flash loan fee and (once first flash loan executes) flash loan fee with data related to s_currentlyFlashLoaning
mapping which will be 0x0...0 since the initial storage slot for mappings is 0x0...0 (with mapping data stored elsewhere).
This can introduce many unexpected issues because wrong state variables are being updated.
src/upgradedProtocol/ThunderLoanUpgraded.sol
After protocol update to ThunderLoanUpgraded.sol
contract, multiple state variables will be overwritten leading to many issues, know and unknown.
Do not change fee precision to a constant
. This will introduce many issues, as explained above.
In addition, do not change order of state variables in ThunderLoanUpgraded.sol
.
Keep state variables in same storage memory slots in ThunderLoanUpgraded.sol
as they are in ThunderLoan.sol
Note: Additional changes will need to be made to
FEE_PRECISION
. Recommended to keep the same implementation withs_feePrecision
as in previous version of the contract inThunderLoan.sol
.
src/upgradedProtocol/ThunderLoanUpgraded.sol
Change is needed in ThunderLoanUpgraded.sol so that the initialize function can run. See H-4
test/unit/ThunderLoanTest.t.sol
Note: Not clear if when this POC is ran, storage variables will be at exact same index like they were for me. The point will still stand though because which ever storage index they are in the fee precision will be overwritten when the update happens.
Manual Audit
Foundry
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.