Submitted by Arabadzhiev, also found by ArmedGoose and blutorque
The current implementation of the PrincipalToken has a flash lending functionality:
And as of now, this functionality is implemented in such a way, that it allows users to borrow the whole IBT balance of the PrincipalToken permissionlessly:
This is fine on its own and it works as it should. However there is a specific case where it can be abused. If the IBT vault prices its shares using the following formula:
$sharePrice = {totalAssets \over totalShares}$
Then, it will fall-back to some default price value when its totalAssets and totalShares values are equal to zero. Most usually that is the value of 1. Such is the case with the OpenZeppelin ERC4626 vault implementation, which is the most commonly used ERC4626 base implementation:
In that case, if the PerincipalToken contract happens to hold all of the IBT supply, a malicious lender can come in and perform the following exploit:
What has just happened in the above described scenario is that the malicious lender has successfully reset the IBT vault share price to its default value, by redeeming all of the vaults shares for all of its underlying assets. Then, they have minted back the previously redeemed shares plus the required flash loan fee shares at the default price and finally paid back the flash loan with those. Ultimately, what the attacker managed to accomplish is that they managed to get totalIBTSupply * (initialIBTPrice - defaultIBTPrice) of underlying IBT assets at the expense of a single flash loan fee, while leaving the PerincipalToken contracts users with a massive loss. More specifically, the users of the contract will lose all of their accumulated yield and potentially even more than that, depending on the IBT price at which they deposited into the PT and how far down it will be able to be deflated.
The following Foundry PoC test demonstrates how the scenario outlined in the Impact section could play out, using Solidity code. It is written on top of the PrincipalToken4 test suite contract, which uses an instance of the MockIBT2 contract as its IBT token, which uses the same share pricing mechanism as the one described above.
In the PrincipalToken::flashLoan function, verify that the IBT rate/price has not decreased once the flash loan has been repaid:
Dravee (Judge) decreased severity to Medium and commented:
yanisepfl (Sponsor) acknowledged via duplicate #240 and commented:
For full discussion, see duplicate issue #240.
For this audit, 11 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by SBSecurity received the top score from the judge.
The following wardens also submitted reports: sl1, Shubham, cheatc0d3, peanuts, DarkTower, 14si2o_Flint, 0xDemon, ArmedGoose, 0xLuckyLuke, and Tigerfrake.
