Closed sherlock-admin2 closed 2 months ago
1 comment(s) were left on this issue during the judging contest.
tsvetanovv commented:
Arbitrage Opportunity are appreciated by the Protocol. You can see the documentation: https://corkfi.notion.site/Litepaper-One-pager-2d846fc6b93f49558e2a185665e94944
eta
High
Arbitrage Opportunity Due to Mismatch in
getAmountIn
andgetAmountOut
Calculations in DsSwapperMathLib.solSummary
The
getAmountIn
andgetAmountOut
functions in theDsSwapperMathLib.sol
contract calculate the required RA assets for purchasing DS assets and the RA assets received from selling DS assets, respectively. However, due to an inconsistency in their calculations, an arbitrage opportunity arises.Vulnerability Detail
The
getAmountIn
function is designed to calculate the amount of RA assets required to purchase a specified amount of DS assets. The result can be simplified tods * (ds / ra)
. ThegetAmountOut
function, on the other hand, calculates the RA assets received from selling a specified amount of DS assets, and its result can be simplified tods / (ds / ra)
.Depeg-swap/contracts/libraries/DsSwapperMathLib.sol:getAmountIn_L77
Depeg-swap/contracts/libraries/DsSwapperMathLib.sol:getAmountOut_L96
The issue is that the result of buying DS assets does not match the result of selling the same amount of DS assets. Specifically,
ds * (ds / ra) != ds / (ds / ra)
. This discrepancy creates an arbitrage opportunity, as the cost to purchase DS assets differs from the amount received when selling the same amount of DS assets.Impact
This discrepancy leads to a pricing imbalance between buying and selling DS assets, allowing users to exploit arbitrage opportunities, potentially draining the contract of RA assets or destabilizing the DS asset price.
Code Snippet
Depeg-swap/contracts/libraries/DsSwapperMathLib.sol:getAmountIn_L77 Depeg-swap/contracts/libraries/DsSwapperMathLib.sol:getAmountOut_L96
Tool used
Manual Review
Recommendation
Adjust the calculations in the
getAmountIn
andgetAmountOut
functions to ensure that the amount of RA required to buy DS assets is consistent with the amount of RA received from selling the same amount of DS assets. This will eliminate the arbitrage opportunity and ensure accurate pricing.