Closed c4-bot-10 closed 9 months ago
bytes032 marked the issue as sufficient quality report
bytes032 marked the issue as duplicate of #196
alex-ppg marked the issue as not a duplicate
The Warden details a potential attack that revolves around front-running as well as the sacrifice of assets.
First, front-running attacks are impossible in Starknet due to the usage of a single FIFO sequencer. The #179 scenario does not rely on a front-run but rather a back-run attack, introducing a transaction after add_yang
is called which is valid.
Secondly, the would-be attacker would have to sacrifice their assets to impact the assets of another, resulting in a net negative for every party involved. Such attacks are not profitable and thus reduce the impact of the exhibit.
Coupling the above facts, this submission does not constitute an HM vulnerability and is better suited as a QA (L) issue.
alex-ppg marked the issue as unsatisfactory: Overinflated severity
Lines of code
https://github.com/code-423n4/2024-01-opus/blob/4720e9481a4fb20f4ab4140f9cc391a23ede3817/src/core/absorber.cairo#L667-L689
Vulnerability details
Impact
It is possible to start griefing users who provide their yin to the
absorber
, making them lose all of their funds in exchange of0
shares (a variation of the vanilla first-depositor front-running attack).Proof of Concept
Like any other ERC4626 vault, the
absorber
implements a deposit function calledprovide
that, in a nutshell, lets users deposit their yin and receive shares of the underlying vault. To prevent the vanilla front-running attack, the first provider must deposit a value higher or equal thanINITIAL_SHARES
, so that he will receive the difference:absorber, function convert_shares
and if we go to the definition of
INITIAL_SHARES
:we see this amount is negligible taking into account the decimals of the yin token (18 as seen here). If we add the fact that
convert_to_shares
can return0
shares andprovide
does not revert if that happens, the next situation arises:provide
with his own yin to participate in absorptions by being credited a certain number of shares. Note that he is the first depositor and lets say the amount provided by Bob isX
INITIAL_SHARES
, so that she receives0
shares ANDself.total_shares = self.yin_erc20().balance_of(absorber) = INITIAL_SHARES
absorber
X * INITIAL_SHARES
, so thatself.yin_erc20().balance_of(absorber) = INITIAL_SHARES + X * INITIAL_SHARES
whilstself.total_shares
remains unchanged0
shares in exchange due to:self.convert_to_shares
norself.provide
do not revert in that situationself.convert_to_shares
does not round up if called fromself.provide
, as the flag is false:X * total_shares / absorber_balance
, and if we plug in the above we haveX * INITIAL_SHARES / (INITIAL_SHARES + X * INITIAL_SHARES) = 0
due to rounding down in integer division ifdenominator > numerator
For reference, check the last example of this post as well as this discussion.
Recommended Mitigation Steps
There are many solution available and you can see some of them here, although I would stick to minting the initial shares when deploying the
absorber
, so that there are no first-depositor attacks nor issues that. Moreover, ifconvert_to_shares
returns0
shares, I would revert to prevent users from providing their yin for nothing.Assessed type
Math