Zaros is getting less fees than expected because of a precision loss against the protocol in MarginCollateralConfiguration::convertUd60x18ToTokenAmount
when decimals are less than Constants.SYSTEM_DECIMALS
.
The deducting fees using TradingAccount::deductAccountMargin
, Zaros uses prb math have a lot of precision but at the moment of sending the fees to the recipient it converts requiredMarginInCollateralX18
(type UD60x18) to amountToTransfer
of type uint256 to execute then the safeTransfer
. However in the process the precision loss is againts the Zaros therefore it recives less fees than expected.
add fs_permissions = [{ access = "read-write", path = "./"}]
to foundry.toml so vm can write to a file the output of the fuzz because console2.log doesn't work.
add import "forge-std/Vm.sol";
to TradingAccount.sol line 22
add TradingAccount.sol
line 157 add a script that write the output of the fuzz to a file
Execute forge test --mt="testFuzz_WhenThereIsNotCollateralLiquidationPriority"
The result will be:
Output:
Initial parameters:
Zaros deduct 2 diffent fees and a pnl reduction when liquidate and then deduct another 2 different fees when fill an order so the precision loss will be happening all the time.
liquidation deductions are settlementFee
, orderFee
and pnlUsdX18
and filling an order are orderFee
and settlementFee
VS Code
It is a standard in the industry to charge fees with the precision in favor of the protocol for accounting, to avoid free operations with dust transactions and avoid an attack vector that can generate loss of funds when having free operations and user incentives at the same time. See Exactly case M-3: Theft of unassigned earnings from a fixed pool
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.