Closed code423n4 closed 2 years ago
Incorrect, the AMM doesn't adjust pricing on a rebase event, traders do that through arbitrage and this is by design.
I will definitely need to look into this for longer, but @0xean it seems like the system is only checking for a negative rebase of the baseToken
exclusively when calling swapQuoteTokenForBaseToken
.
I'm guessing the negative-rebase check is there to ensure there's enough liquidity for the swap (while using internal balances for the pricing / ratio), while on a positive rebase you wouldn't care and instead you'd use the internal balances again for pricing?
If that's the case, I'm guessing the "worst case scenario" is that you'd have some dust due to rebalances left if traders exclusively bought and sold, while the liquidity provider would actually have a way to arb out those differences.
Am I understanding the system correctly?
Per the information that I have, available here: https://github.com/ElasticSwap/elasticswap/blob/develop/ElasticSwapMath.md
The math is used to swap from baseToken
(rebasing or not) to quoteToken
(never rebasing)
As such, while there may have been a rebase (which can be arbed away through single sided liquidity provision or by doing the opposite swap), due to the AMM guarantees, all the math can be performed via the storage variables.
Considering:
Am going to mark the finding invalid
Handle
Meta0xNull
Vulnerability details
Impact
When Rebase Event Happen, the curve change and affect Pricing for Both Buy & Sell.
calculateBaseTokenQty() Do Check if Experience Quote Token Decay / a Rebase Down event and Adjust Curve, But calculateQuoteTokenQty() Does Not Check. Thus calculateQuoteTokenQty() may have a Wrong Curve after Rebase Event.
Proof of Concept
https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L611-L637 https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L657-L681
Tools Used
Manual Review
Recommended Mitigation Steps
Check Rebase Event for calculateQuoteTokenQty() and Adjust Curve if Needed.