Open code423n4 opened 1 year ago
JeffCX marked the issue as primary issue
JeffCX marked the issue as high quality report
LybraFinance marked the issue as sponsor confirmed
0xean marked the issue as satisfactory
0xean marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/token/EUSD.sol#L299-#L306 https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/token/EUSD.sol#L414-#L418
Vulnerability details
Impact
Proof of Concept
Currently, the function
EUSD.mint
calls functionEUSD.getSharesByMintedEUSD
to calculate the shares corresponding to the input eUSD amount:As you can see in the comment after
sharesAmount
is checked,//EUSD totalSupply is 0: assume that shares correspond to EUSD 1-to-1
. The code assumes that ifsharesAmount = 0
, thentotalSupply
must be 0 and the minted share should equal to input eUSD. However, that's not always the case.Variable
sharesAmount
could be 0 iftotalShares *_EUSDAmount
<totalMintedEUSD
because this is integer division. If that happens, the user will profit by calling mint with a small EUSD amount and enjoys 1-1 minting proportion (1 share for each eUSD). The reason this can happen is becauseEUSD
supportburnShares
feature, which remove the share of a users but keep thetotalSupply
value.For example:
burnShares
by1e18-1
, after this, contract contains 1e18 eUSD and 1 share, which mean 1 share now worth 1e18 eUSDmint
with 1e18 eUSD, then she receives 1 share (since 1 share worth 1e18 eUSD)mint
with 1e17 eUSD, she will receives 1e17 shares although 1 share now worth 1e18 eUSD. This happens because1e17 * (totalShares = 2) / (totalMintedEUSD = 2e18)
= 0Below is POC for the above example, I use foundry to run tests, create a folder named
test
and save this to a file namedeUSD.t.sol
, then run it using command:forge test --match-path test/eUSD.t.sol -vvvv
Tools Used
Manual Review
Recommended Mitigation Steps
I recommend checking again in
EUSD.mint
function ifsharesAmount
is 0 andtotalSupply
is not 0, then exit the function without minting anything.Assessed type
Math