Open code423n4 opened 1 year ago
JeffCX marked the issue as primary issue
LybraFinance marked the issue as sponsor disputed
Our plan is to only swap for USDC.
0xean changed the severity to QA (Quality Assurance)
LybraFinance marked the issue as sponsor acknowledged
0xean marked the issue as grade-a
Lines of code
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/configuration/LybraConfigurator.sol#L298-L305
Vulnerability details
In
LybraConfigurator::distributeRewards
, if there is enoughEUSD
balance, some part of income may be exchanged to another stablecoin, calledstableToken
. It is only exchanged whenpremiumTradingEnabled && price > 1005000
, whereprice = curvePool.get_dy_underlying(0, 2, 1e18)
and according to Curve Docs (https://curve.readthedocs.io/factory-pools.html),get_dy_underlying
returns amount of tokens received. So, in essence, function will check how much of stablecoins will the contract receive for1 EUSD
and if the amount is too low (<= 1005000
=1.005
in case of6
- decmial tokens), the swap won't take place andEUSD
s will just be transfered tolybraProtocolRewardsPool
.It will work fine for
6
- decimal stablecoins, likeUSDC
, but will not work correctly in case of those that have more decimals, for instanceBUSD
(has18
) - of course,BUSD
will probably cease to exist in several months, but, still, stablecoins with18
decimals exist.In case of such stablecoins, the condition
price <= 1005000
will almost always be false, even if1 EUSD = 0.000001 BUSD
, so the protocol may perform a very unprofitable swap (of course, it may also be1 EUSD = 0.95 BUSD
due to a temporary depeg - protocol will still lose value).Impact
Protocol may do unprofitable swaps, thus value is leaked. Since there is a leak of value and it's conditional (non-
6
-decimal stablecoin has to be used), the issue is classified as Medium.Proof of Concept
BUSD
is used as a stablecoin in configurator.EUSD
- it happens from time to time; it also happened in the past to other collateralised stablecoins, such asDAI
(whenUSDC
depegged). So, assume that1 EUSD = 0.95 BUSD = $0.95
.premiumTradingEnabled
is true.EUSD
is above or equal$1.005
:https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/configuration/LybraConfigurator.sol#L298-L305
Tools Used
VS Code
Recommended Mitigation Steps
Change
price <= 1005000
inif
toprice <= 1005 * 10**stableToken.decimals() / 1000
.Assessed type
Decimal