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 disagree with severity
I think this is mostly a design consideration and thus QA
0xean changed the severity to QA (Quality Assurance)
LybraFinance marked the issue as sponsor confirmed
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#L213-L217 https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/pools/base/LybraEUSDVaultBase.sol#L295-L302 https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/pools/base/LybraPeUSDVaultBase.sol#L230-L239
Vulnerability details
Fees for protocol are calculated incorrectly in
LybraEUSDVaultBase
andLybraPEUSDVaultBase
. New fees are calculated as follows:They are updated whenever a user performs some important action, like
repay
and only the newest fee value is used, even if it was different for the entire time.The following scenarios could happen:
vaultMintFeeApy
is set to a high value (say 2%) -> some user deposits assets -> after 1 year, fees are reduced (say, to 1%) -> user didn't do anything with his loan for the last year and now he spots that fee decreased, so he performs a dummy transaction so thatfeeStored
for him is calculated using the new fee - it will reduce his fee twice, although he should pay the 2% fee for that yearvaultMintFeeApy
is set to a low value (say 1%) -> some user deposits assets -> after 1 year, fees are increased (say, to 2%) -> user didn't do anything with his loan for the last year, so the fee wasn't updated for him, but now he decides to do some action which will update his fee (for instance can repay some part of his debt) -> protocol will calculate fee as 2% for the entire year, despite that it was 1% and just changed a while ago to 2%Impact
Protocol will lose some income, or users will pay higher fees than they should. From Code4Rena docs:
Here, value is leaked, but there are external requirements:
Hence, this submission was classified as Medium.
Proof of Concept
Please run the following hardhat test:
It's necessary to replace with a valid RPC URL and to fix wrong interface in
LybraWBETHVault
. Please also changefeeStored
mapping inLybraPeUSDVaultBase.sol
to public.Tools Used
VS Code
Recommended Mitigation Steps
It seems that there is no good mitigation - if we wanted to calculate fees precisely, some additional mapping with time intervals and fees during these intervals would have to be introduced, but this would make transactions more expensive for users, since
_newFee
would read from storage every time. Alternatively, one of the following options could be chosen:Assessed type
Other