HydraDX-node icon indicating copy to clipboard operation
HydraDX-node copied to clipboard

[Audit_RV]Bug: Rounding error could cause loss to the pool

Open yanliu18 opened this issue 2 years ago • 0 comments

The AMM state machine in Omnipool operates in integer domain, where rounding is needed at each state change. We provided an analysis of the rounding effect with a special focus on the AMM state variables. In some cases, the rounding difference is significant and could result in a loss to the pool. We will highlight such cases in this issue. For a full ist of the analysis please refer to our audit report.

Description

  • [ ] Refer to the audit report, Section Operation:Remove Liquidity - Conclusion-Rounding error analysis- delta_reserve. The rounding difference of $$\Delta Balance$$ is bounded within the range $$(-1, Unit_{asset_id}^{token/share})$$. It could be possible that there are more asset paid out from the pool than it should be, resulting a loss to the pool.

  • [ ] The audit report Section Operation:Remove Liquidity - Conclusion-Rounding error analysis- the changes to imbalance, when the current price drops below the invested price, the rounding difference for updated imbanalnce could be within the range

$$(-\frac{Price_{asset} * Imbalance_{LRNA}.value * Unit_{asset}^{token/share}}{BalanceLRNA},\frac{Price_{asset} * Imbalance_{LRNA}.value}{Balance_{LRNA}}+1)$$, where a significant rounding error could happen. It is recommended to redesign the rounding strategy such that the rounding effect is within a small and controllable range.

  • [ ] In the audit report Section Operation:Sell asset_in for asset_out, no LRNA - Conclusion-Invariant Checking #1, due to rounding effect, the constant products will increase [0, Reserve_asset_in +amount) for the asset_in/LRNA subpool and [0, hub_reserve_asset_out + hub_reserve_asset_in) for the asset_out/LRNA subpool.

  • [ ] In the audit report Section Operation:Operation: Buy asset_out using asset_in, none is LRNA - Conclusion-Rounding Analysis #1, the rounding effect on delta_hub_reserve_asset_out could be very large when the amount requested to buy is large enough, indicated by the range

$$(-\frac{hubreserve_{out} * amount}{((1-AssetFee) * reserve_{out}+1 - amount)*((1-AssetFee)*reserve_{out} - amount)},1]$$. The rounding effect is accumulated for other AMM state variables, since they are computed based on delta_hub_reserve_asset_out.

  • [ ] Similar to the above, buying asset using LRNA, would also have a rounding error that could effect the AMM state unfavoriably.

yanliu18 avatar Sep 07 '22 05:09 yanliu18