Closed c4-bot-9 closed 6 months ago
Consider QA. Report does not give evidence on why the below statement will happen.
The impact is if one or more on_finalize() is missed or failed, the block-based trading limit(AllowedTradeVolumeLimitPerAsset) will continue to use a value calculated based on a historic block.
0xRobocop marked the issue as insufficient quality report
0xRobocop marked the issue as primary issue
Why should the on_finalize
call be "missed" or fail (with its very simple logic that clears 3 values)? It is required that this function is always executed at the end of a block: https://docs.substrate.io/learn/transaction-lifecycle/
OpenCoreCH marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/circuit-breaker/src/lib.rs#L430
Vulnerability details
Impact
Circuit breaker is vulnerable to
on_finalize()
miss or fail, at risk of outdated trading or liquidity limit leading to over-trading.Proof of Concept
Both ema-oracle pallet and circuit-breaker pallet are dependent on
on_finalize()
call at the end of a block.The problem is that ema-oracle pallet has a mechanism to handle
on_finalize()
miss or fail, but circuit-breaker pallet doesn't have any mechanism to handle it.The impact is if one or more
on_finalize()
is missed or failed, the block-based trading limit(AllowedTradeVolumeLimitPerAsset
) will continue to use a value calculated based on a historic block.At a beginning of a new block,
AllowedTradeVolumnLimitPerAsset
value is supposed to be clear already byon_finalize()
of the previous block. However, ifon_finalize()
fails,AllowedTradeVolumnLimitPerAsset
is not cleared andinitialize_trade_limit()
will do nothing and continually use an old limit.(https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/circuit-breaker/src/lib.rs#L430)
If the situation persists,
initialize_trade_limit()
will continue to be skipped. If the old limit is too large relative to the reserve of current block, users can over-trade; Or if the old limit is small or comparable relative to the current reserve, trading can be DOSsed.Tools Used
Manual
Recommended Mitigation Steps
In
initialize_trade_limit()
, add an additional check on the current block number, if the current block number changes, run theif
body to initialize the trade limit.Assessed type
Other