When a maker creates an ask offer, the deposit amount is rounded up.
When a maker closes an ask offer, the refunded amount is rounded down.
The difference between them can lead to loss of fund in case of low decimal collateral tokens.
When maker creates an ask offer, the transfer amount is rounded up:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L92
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/libraries/OfferLibraries.sol#L44
If this offer is closed, the transferred amount is added to the balance of the maker as a MakerRefund
to be able to withdraw it later. The amount is rounded down:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L450
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/libraries/OfferLibraries.sol#L86
It shows that the maker loses some amount by just creating and closing an ask offer due to the rounding.
Please note that the decimal of the token (i.e. the collateral token) is unknown to us, and it depends on the admin that which tokens will be whitelisted. So, if the whitelisted token has low number of decimals, this rounding issue will have more impact on the makers.
For example two standard erc20 tokens with zero decimals are:
https://etherscan.io/address/0xaec2e87e0a235266d9c5adc9deb4b2e29b54d009#code
https://etherscan.io/token/0x1da4858ad385cc377165a298cc2ce3fce0c5fd31#code
Moreover, there is no mechanism in the protocol to withdraw these stuck fund in the protocol.
In this test Alice (maker) creates an ask offer to sell 1000 points for 1 collateral token (assuming that the decimal of the collateral token is small in order of 0, 1, 2). Because of rounding up, Alice should transfer 2 collateral token. Then, Alice closes her offer. Due to rounding down, Alice only receives 1 collateral token into her balance. So, she loses 1 collateral token.
The output is:
Loss of fund due to non-similar rounding direction during creating and closing an offer.
The direction of rounding for this case should be similar.
Duplicate of #456, however, for issues noting rounding directions, will be low severity given the impact is not proven sufficiently with a PoC/numerical example and most rounding will not result in significant losses e.g. most examples only proved at most a 1 wei difference when computing `depositAmount/platFormFees` and involves lower amount offers
Duplicate of #456, however, for issues noting rounding directions, will be low severity given the impact is not proven sufficiently with a PoC/numerical example and most rounding will not result in significant losses e.g. most examples only proved at most a 1 wei difference when computing `depositAmount/platFormFees` and involves lower amount offers
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.