The value of a share in the vault (ie, one asset token) should never decrease as the result of a deposit, redemption, or flash loan. (In the case of a flash loan, it should always increase.) The value of one asset token is equal to TotalAssets (total underlying tokens in the AssetToken contract) / TotalSupply (number of outstanding asset tokens or shares). The number of asset token shares and the number of underlying tokens in the vault can decrease or increase (depending on deposits, redemptions, and flash loans), but the value of each asset token share should not decrease.
To prevent any funny business, you can add post checks to the end of these functions that the value of one asset token has not decreased (or, in the case of flashloan, that it has increased). This would prevent an attacker from, e.g., exploiting a reentrancy to drain all the underlying tokens.
This gives extra security in case you overlook a bug that could otherwise be exploited by enforcing an invariant.
Manual review
Foundry
Add post checks to deposit, redeem, and flash loan. Make these changes:
Add a TotalAssets function to AssetToken.sol:
Then for deposit, redeem, and flash loan, add the following at the beginning of the function to get the initial value of an asset token before the transaction:
Then, at the end of the deposit and redeem functions, add:
And, at the end of the flash loan function, add this to make sure the flash loan increase the value of each asset token share:
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.