DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: medium
Valid

SEV 6: priceFeedHeartbeatSeconds value of markets cannot be initialized

Severity: Medium

Summary

Because MarketConfiguration::update function does not set the priceFeedHeartbeatSeconds value, the priceFeedHeartbeatSeconds cannot be initialized and will always be 0.

The PerpMarket::getIndexPrice function uses the priceFeedHeartbeatSeconds value and the function reverts for most transactions except for transactions which are included after the chainlink price-feed update in the same block.

The PerpMarket::getIndexPrice function is used in all market operations: createMarketOrder, _fillOrder, liquidate and withdrawMargin(if there's a open position). Traders transactions might succeed or fail.

Considering the chances that fillOfflineOrder might be called in the same block as chainlink update are non-negligible, a position might be opened for some traders.

The traders with open position cannot close their position unless the transaction is included in the block with the future chainlink updates for the market resulting in temporary freeze of assets for the traders.

Vulnerability Details

Definition of the MarketConfiguration::update function: MarketConfiguration.sol#L37-L49

The MarketConfiguration::update function does not set the priceFeedHeartbeatSeconds. The value is 0 for all perp markets.

The PerpMarket::getIndexPrice function calls the ChainlinkUtil::getPrice function and passes the priceFeedHeartbeatSeconds of the market.

Snippet of PerpMarket::getIndexPrice calling ChainlinkUtil::getPrice: PerpMarket.sol#L83-L85

The ChainlinkUtil::getPrice function fetches the latestRoundData from the feed and reverts if block.timestamp - updatedAt > priceFeedHeartbeatSeconds.

Snippet of ChainlinkUtil::getPrice function checking the heart beat seconds: ChainlinkUtil.sol#L60-L62

Given priceFeedHeartbeatSeconds is always 0, the getPrice function reverts if block.timestamp != updatedAt. As a result, the getPrice function succeeds if and only if the chainlink feed was updated in the same block.

Impact

The Zaros protocol is not usable with the current implementation. Most of the trading operation transactions will fail. If any operation succeeds then it leads to temporary freeze of trader's collateral.

Tools Used

Manual Review

Recommendations

Update MarketConfiguration::update function to initialize priceFeedHeartbeatSeconds value.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`MarketConfiguration::update` function lacks `priceFeedHeartbeatSeconds` argument

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.