Platform: Code4rena
Start Date: 09/12/2022
Pot Size: $36,500 USDC
Total HM: 9
Participants: 69
Period: 3 days
Judge: Picodes
Total Solo HM: 2
Id: 190
League: ETH
Rank: 59/69
Findings: 1
Award: $28.12
π Selected for report: 0
π Solo Findings: 0
π Selected for report: 0xSmartContract
Also found by: 0Kage, 0x52, 0xAgro, 0xNazgul, 0xTraub, 0xhacksmithh, Awesome, Aymen0909, Bnke0x0, Englave, Janio, Mukund, Parth, RaymondFam, Rolezn, SmartSek, Tointer, UdarTeam, Udsen, Zarf, caventa, chaduke, csanuragjain, deliriusz, gz627, idkwhatimdoing, izhelyazkov, joestakey, neumo, obront, oyc_109, rvierdiiev, shark, trustindistrust, wait, yongskiws
28.124 USDC - $28.12
https://github.com/prepo-io/prepo-monorepo/blob/3541bc704ab185a969f300e96e2f744a572a3640/apps/smart-contracts/core/contracts/Collateral.sol#L47-L48 https://github.com/prepo-io/prepo-monorepo/blob/3541bc704ab185a969f300e96e2f744a572a3640/apps/smart-contracts/core/contracts/Collateral.sol#L66-L67
Tokens with a small amount of decimals might result in a revert when calculating _fee
in the deposit()
function of Collateral.sol
. The fee is calculated as follows:
uint256 _fee = (_amount * depositFee) / FEE_DENOMINATOR;
Letβs assume the base token is EURS wich has 2 decimals (https://etherscan.io/token/0xdb25f211ab05b1c97d595516f45794528a807ad8#readProxyContract#F4).
When depositing 9 EURS while the collateral deposit fee is 0,1%, the fee will be calculated as follows:
uint256 _fee = 900 * 1000 / 1000000 = 0
This will result in a _fee
of 0. Subsequently, the next line will result in a revert, making it impossible for the user to deposit funds and receive collateral tokens.
The same applies to the withdraw function when withdrawing collateral tokens for the underlying base token.
Depending on the used base layer token, smaller amounts of the token can not be deposited for withdrawn for collateral. As most tokens are using 6 or more decimals, the impact is rated as medium.
Manual Review
In order to support tokens with smaller decimals and still receive a fee, mulDivUp
from FixedPointMathLib might be used (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol). This guarantees the fee is at least 1 in case the divide by FEE_DENOMINATOR
might result in zero.
#0 - Picodes
2022-12-14T07:48:51Z
Even in your scenario the minimal amount would be 10 EURS, so in the worst case users have to pay at least 0.01 EUR of fees.
#1 - Picodes
2022-12-14T07:49:19Z
So I don't think this could reasonably break the contract's functionality
#2 - c4-judge
2022-12-14T07:49:30Z
Picodes changed the severity to QA (Quality Assurance)
#3 - c4-judge
2022-12-19T13:43:14Z
Picodes marked the issue as grade-b