Penrose::_depositFeesToTwTap can unexpectedly revert due to amount rounded down
The function _depositFeesToTwTap recomputes the fee amount from shares after withdrawal, which can differ from the actual withdrawn amount due to rounding, causing the transfer to revert. This can block fee withdrawals in some cases.
Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/43
Found by
cergyk, ctf_sec
Summary
_depositFeesToTwTap computes the amount of fees withdrawn after having it withdrawn. There may be a difference with actual fees withdrawn which could cause the function to revert unexpectedly
Vulnerability Detail
We can see the fees being withdrawn here, but instead of using the amount withdrawn, the amount is recomputed from shares here
This can be problematic if during first call the fee amount is rounded down, but after being withdrawn, it is not being rounded down
Example
- before withdrawal:
base: 7 elastic: 13 share: 2
amount withdrawn: 13*2/7 = 3 shares deducted = 2
- after withdrawal:
base: 5 elastic: 10 share: 2
amount computed: 10*2/5 = 4
The transfer reverts because only 3 has been withdrawn
Impact
The call will withdraw unexpectedly in some cases, dosing fees withdrawal
Code Snippet
Tool used
Manual Review
Recommendation
Compute the amount of fees which will be withdrawn before making the actual withdrawal in _depositFeesToTwTap
Discussion
nevillehuang
request poc
Seems valid, however, is there a workaround to prevent this DoS? Also the example is not representative of scaled actual values.
sherlock-admin3
PoC requested from @CergyK
Requests remaining: 6
cryptotechmaker
Fixed in https://github.com/Tapioca-DAO/Tapioca-bar/pull/353
sherlock-admin4
The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/pull/353.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The fee amount is recomputed from shares after withdrawal instead of using the actual withdrawn amount, leading to rounding discrepancies.
Impact
The call will withdraw unexpectedly in some cases, causing a denial of service for fee withdrawals.
What the attacker needed
None
The fix
The issue was fixed by computing the fee amount before making the withdrawal.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a contract withdraws fees, it first takes out some tokens and then calculates how many tokens it got. If the calculation uses a different method than the actual withdrawal, the numbers can mismatch because of rounding. This mismatch can cause the contract to try to send more tokens than it has, making the transaction fail.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.