`KeeperOracle.commit` will revert and won't work for all markets if any single `Market` is paused
The KeeperOracle contract's commit function iterates over all markets that requested a price and calls update on each, but if any market's update reverts (e.g., because the market is paused), the entire commit reverts. This can temporarily brick the oracle and stop trading in all other markets sharing the same KeeperOracle instance.
Source: https://github.com/sherlock-audit/2023-10-perennial-judging/issues/26
Found by
panprog
Summary
According to protocol design (from KeeperOracle comments), multiple markets may use the same KeeperOracle instance:
/// @dev One instance per price feed should be deployed. Multiple products may use the same
/// KeeperOracle instance if their payoff functions are based on the same underlying oracle.
/// This implementation only supports non-negative prices.
However, if KeeperOracle is used by several Market instances, and one of them makes a request and is then paused before the settlement, KeeperOracle will be temporarily bricked until Market is unpaused. This happens, because KeeperOracle.commit will revert in market callback, as commit iterates through all requested markets and calls update on all of them, and update reverts if the market is paused.
This means that pausing of just 1 market will basically stop trading in all the other markets which use the same KeeperOracle, disrupting protocol usage. When KeeperOracle.commit always reverts, it's also impossible to switch oracle provider from upstream OracleFactory, because provider switch still requires the latest version of previous oracle to be commited, and it will be impossible to commit it (both valid or invalid, requested or unrequested).
Additionally, the market's update can also revert for some other reasons, for example if maker exceeds the maker limit after invalid oracle as described in the other issue.
And for another problem (although a low severity, but caused in the same lines), if too many markets are authorized to call KeeperOracle.request, the markets callback gas usage might exceed block limit, making it impossible to call commit due to not enough gas. Currently there is no limit of the amount of Markets which can be added to callback queue.
Vulnerability Detail
KeeperOracle.commit calls back update in all markets which called request in the oracle version:
for (uint256 i; i < _globalCallbacks[version.timestamp].length(); i++)
_settle(IMarket(_globalCallbacks[version.timestamp].at(i)), address(0));
...
function _settle(IMarket market, address account) private {
market.update(account, UFixed6Lib.MAX, UFixed6Lib.MAX, UFixed6Lib.MAX, Fixed6Lib.ZERO, false);
}
If any Market is paused, its update function will revert (notice the whenNotPaused modifier):
function update(
address account,
UFixed6 newMaker,
UFixed6 newLong,
UFixed6 newShort,
Fixed6 collateral,
bool protect
) external nonReentrant whenNotPaused {
This means that if any Market is paused, all the other markets will be unable to continue trading since commit in their oracle provider will revert. It will also be impossible to successfully switch to a new provider for these markets, because previous oracle provider must still commit its latest request before fully switching to a new oracle provider:
function _latestStale(OracleVersion memory currentOracleLatestVersion) private view returns (bool) {
if (global.current == global.latest) return false;
if (global.latest == 0) return true;
@@@ if (uint256(oracles[global.latest].timestamp) > oracles[global.latest].provider.latest().timestamp) return false;
if (uint256(oracles[global.latest].timestamp) >= currentOracleLatestVersion.timestamp) return false;
return true;
}
Impact
One paused market will stop trading in all the markets which use the same oracle provider (KeeperOracle).
Code Snippet
KeeperOracle.commit iterates all requested markets and settles them:
https://github.com/sherlock-audit/2023-10-perennial/blob/main/perennial-v2/packages/perennial-oracle/contracts/keeper/KeeperOracle.sol#L123-L124
_settle calls update on the market:
https://github.com/sherlock-audit/2023-10-perennial/blob/main/perennial-v2/packages/perennial-oracle/contracts/keeper/KeeperOracle.sol#L176-L178
Market.update has whenNotPaused modifier, making it revert when paused:
https://github.com/sherlock-audit/2023-10-perennial/blob/main/perennial-v2/packages/perennial/contracts/Market.sol#L87
Tool used
Manual Review
Recommendation
- Consider catching and ignoring revert, when calling
updatefor the market in the_settle(wrap in try .. catch). - Consider adding a limit of the number of markets which are added to callback queue in each oracle version, or alternatively limit the number of authorized markets to call
request.
Discussion
kbrizzle
Markets are currently only pausable Factory-wide, which means this cannot happen unless there is a multi-MarketFactory setup pointing at the same Oracle instance.
While valid, we currently do not support this usage pattern, and this would be among many improvements we'd need to make to.
panprog
This issue is not limited to paused markets, but can happen for any reasons when market.update reverts, for example in the current codebase this can happen if maker exceeds makerLimit (issue #24), which will revert all update calls, subsequently bricking oracle update for all markets. This is mentioned in the issue description:
Additionally, the market's
updatecan also revert for some other reasons, for example if maker exceeds the maker limit after invalid oracle as described in the other issue.
I think this should be medium. It is still valid with paused markets (even if not considered supported setup by sponsor), but also valid if any other issue causes market to revert updates. This issue will make #24 more severe (#24 bricks 1 market, #26 makes it brick oracle commit and all markets using the same oracle)
kbrizzle
Thanks for the additional color.
We'd like to preserve the guarantee that each posted price will atomically settle the attached market(s) (globally / async for locally) to that version. This is important for a number of parameter improvements and future upgrades we have planned.
If there are settlement-revert cases that are possible given this paradigm, we'd like to address those as if they are market-bricking issues.
We're open to however you think this is fair to judge on a severity basis, but we will only be resolving actual revert issues versus making the settlement callback try...catch.
panprog
These are the planned future upgrades, but according to Sherlock rules it should be judged based on current code. In the current code there are no problems if market is not settled, but there are problems if due to some other issues (such as #24) the issue described here makes single market failure cause all the markets using the same oracle revert.
I'd like to add that while multi-factory setup is not supported, multi markets (from the same factory) pointing to the same oracle instance is supported. So the following setup is supported:
- MarketFactory1 deploys Market1 and Market2
- OracleFactory1 deploys Oracle1
- Market1 oracle is set to Oracle1 (say, it uses no payoff)
- Market2 oracle is set to Oracle1 (say, it uses 2x payoff - so a 2x market for the same underlying oracle)
In such setup, if Market1 is paused, then Market2 is paused too (because they're paused via MarketFactory1, markets don't have pause function by themselves). However, if Market1 maker exceeds makerLimit due to #24, then not only Market1 is bricked (reverts all updates), but also both Oracle1 and Market2 are bricked too (revert all commit and update transactions).
So while most of this issue description is about pause function (since I didn't know about multi-factory setup not being supported), which can be considered invalid due to not being supported, the description also does mention the other reasons for the issue to happen, including making the maker > makerLimit issue more severe (possibly some other issues which can revert update too). So this part is valid, so I believe it should be medium
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The commit function does not handle reverts from individual market update calls, so a single failing market causes the entire transaction to revert.
Impact
One paused market (or any market whose update reverts) can stop trading in all markets that share the same KeeperOracle, and it also prevents switching to a new oracle provider.
What the attacker needed
Multiple markets share one KeeperOracle; at least one market's update reverts (e.g., paused)
The fix
The report recommends wrapping the market update call in a try-catch to ignore reverts, or limiting the number of markets in the callback queue.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A price oracle feeds prices to trading markets. This oracle lets multiple markets ask for a price at once, then tries to update all of them in one go. If one market refuses the update (for example, because it is paused), the whole batch fails, so the price never gets recorded and every other market using that oracle is stuck.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.