-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: pool domination attack #17
Conversation
@PawelTroka need help fixes the failing test. |
@0xmichalis please take a look, very interested in your opinion. |
@kosecki123 ok, but this won't work for e.g. amounts lower than 10, because 10% then yields 0 fee, right? |
I think that's ok, this means that we can be left with tiny amount of credits which, unless we deposit more, we won't be able to redeem. |
src/FeeCalculator.sol
Outdated
uint256 fee = intoUint256(amount_float * (singleAssetRedemptionRelativeFee)); | ||
return fee; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, is this ok if it rounds down to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In such case, because of
require(totalFee > 0, "Fee must be greater than 0");
protocol will fail
This means we cannot support redemption of amount <= 10 from the highly dominated pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kosecki123 when you say amount <= 10
that is in wei, right?
Just to understand this better, redeeming the asset that has 1 wei left in the pool is locked, right? The other asset still has 100e18 in the pool and that should be redeemable without an issue. Does that sound right? |
No, redeeming any asset from the pool will fail, hence this is considered the attack. |
I see now. This is based on how the ratios are calculated in |
a30ecb7
to
e62518a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR fixes the possible attack scenario such that:
Pool now is locked, because of tiny current/total is 1, yielding 0 fee, which results in assert failing.
Context:
Protocol has the assert (fee > 0) to stop the situation where privileged user, miner/validator, can execute very small deposits/redemption (by splitting the amount into small chunks) and thus being able to infinitely modify the pool with 0 fees paid.
Proposed solution:
Since we cannot calculate fee, given the precision it yields 0. We resort to applying fixed fee which is equal to maximum fee for the redemption function, 30% currently.
Using 30% will not break the invariant such that multiple many small "dust" deposits will be cheaper than 1 deposit.