Current heartbeat implementation may lead to a prolonged DoS for Chainlink Oracles
The heartbeat recalibration function sets the expected update interval to the second-largest gap between the last 50 Chainlink updates, so a period of rapid updates can make the oracle appear dead after just one minute of inactivity. An attacker can call recalibrate to disable the market that uses the oracle, causing bad debt or griefing.
Submitted by 00xSEV
Currently, if there are 50 fast updates followed by no updates, a Chainlink Oracle will be considered dead, even though it’s normal behavior. Chainlink Oracles update either after some time has passed or upon a price change.
Vulnerability Details
How it will revert:
There is a _chainLinkIsDead function that returns true if the last update took longer than the heartbeat. See here.
unchecked {
upd = block.timestamp < upd
? block.timestamp
: block.timestamp - upd;
return upd > heartBeat[_tokenAddress];
}
It’s essentially called on every request to the Chainlink Oracle, before the actual call, to ensure the price is up to date.
How does recalibrate work?
heartBeat is updated when recalibrate/recalibrateBulk is called. Anyone can call them. Both of these functions call _recalibrate. See here.
heartBeat[_tokenAddress] = _recalibratePreview(
_tokenAddress
);
In _recalibratePreview, we see that currentSecondBiggest is returned, representing the second-largest difference between updates. Thus, heartBeat is set to the second-largest time difference between two consecutive updates in the last 50 updates. iterationCount is capped by MAX_ROUND_COUNT in _getIterationCount, which is set to 50.
How do Chainlink updates work?
Aggregators receive updates from the Oracle network only when the Deviation Threshold or Heartbeat Threshold triggers an update during an aggregation round. The first condition that is met triggers an update to the data.
- Deviation Threshold: A new aggregation round starts when a node identifies that the off-chain values deviate by more than the defined deviation threshold from the onchain value. Individual nodes monitor one or more data providers for each feed.
- Heartbeat Threshold: A new aggregation round starts after a specified amount of time from the last update.
If you check “Show more details” here, you can see that for most feeds, deviation is set to 1-2% and heartbeat is 86400s = 24 hours. However, some feeds are set to 0.5% or even less.
If there’s a period of high volatility followed by no volatility, it’s possible that heartBeat in Wise will be set to a low value. Consequently, the Chainlink feed will be considered dead after a short period of no updates.
E.g., if there are 50 updates, once every minute, followed by 10 hours of no updates, and then no updates for an additional 24 hours, the heartBeat will be set to 1 minute in Wise. Consequently, the Oracle will be considered dead after 1 minute of no updates. This means it will be considered dead for the initial 10 hours, then considered alive for 1 minute, and then considered dead again for the following 24 hours.
Examples demonstrating similar events in the wild can be seen in this Dune dashboard.
Impact
The Chainlink Oracle is considered dead for a substantial amount of time, affecting liquidations, deposits, withdrawals, and all other functions using this Oracle.
The attacker can disable the entire market that uses the Oracle by calling recalibrate. This can lead to bad debt (the price changes rapidly, but the Oracle still reverts after the first update), griefing (users cannot use the protocol), etc.
It can be even worse if combined with block stuffing or when the gas price is too high and Chainlink does not update. The updates stop coming as often as usual, and the feed is considered dead long enough to accrue bad debt. For example, if the last 50 updates occurred every minute, a sudden spike in demand for block space could make updates come only once an hour, preventing liquidations for 1-2 hours.
Proof of Concept
forge test -f https://mainnet.infura.io/v3/YOUR_KEY -vvv --mt testOne --mc ChainlinkDies$
contracts/Tests/ChainlinkDies.t.sol
pragma solidity =0.8.24;
import "forge-std/console.sol";
import "forge-std/Test.sol";
import "../WiseOracleHub/OracleHelper.sol";
contract OracleHelperMock is OracleHelper {
constructor(
address _wethAddress,
address _ethPriceFeed,
address _uniswapV3Factory
) Declarations(_wethAddress, _ethPriceFeed, _uniswapV3Factory) {
}
function addOracle(
address _tokenAddress,
IPriceFeed _priceFeedAddress,
address[] calldata _underlyingFeedTokens
) external {
_addOracle(
_tokenAddress,
_priceFeedAddress,
_underlyingFeedTokens
);
}
function recalibrate(
address _tokenAddress
)
external
{
_recalibrate(_tokenAddress);
}
function chainLinkIsDead(
address _tokenAddress
)
external
view
returns (bool)
{
return _chainLinkIsDead(_tokenAddress);
}
}
interface PartialAccessControlledOffchainAggregator is IPriceFeed {
function disableAccessCheck() external;
function owner() external returns (address);
function checkEnabled() external returns (bool);
}
contract ChainlinkDies is Test {
address WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address ETH_PRICE_FEED = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;
address UNISWAP_V3_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
address FEI = 0x956F47F50A910163D8BF957Cf5846D573E7f87CA;
PartialAccessControlledOffchainAggregator FEI_ETH_FEED =
PartialAccessControlledOffchainAggregator(0x4bE991B4d560BBa8308110Ed1E0D7F8dA60ACf6A);
uint LAST_NORMAL_BLOCK = 16_866_049;
// one block before the update after no updates for a day
uint TARGET_BLOCK = 16_872_122;
function testOne() external {
OracleHelperMock sut = _test(LAST_NORMAL_BLOCK);
assertFalse(sut.chainLinkIsDead(FEI));
sut = _test(TARGET_BLOCK);
assert(sut.chainLinkIsDead(FEI));
}
function _test(uint blockNumber) internal returns (OracleHelperMock) {
vm.rollFork(blockNumber);
vm.prank(FEI_ETH_FEED.owner());
FEI_ETH_FEED.disableAccessCheck();
assertFalse(FEI_ETH_FEED.checkEnabled());
OracleHelperMock sut = new OracleHelperMock(WETH_ADDRESS, ETH_PRICE_FEED, UNISWAP_V3_FACTORY);
// make sure recalibrate works
sut.addOracle( {
_tokenAddress: FEI,
_priceFeedAddress: FEI_ETH_FEED,
_underlyingFeedTokens: new address[](0)
} );
sut.recalibrate(FEI);
console.log("block:", blockNumber);
console.log("chainLinkIsDead:", sut.chainLinkIsDead(FEI));
return sut;
}
}
Recommended Mitigation Steps
Consider setting Chainlink’s native heartbeat instead. Also consider adding access control to recalibrate functions and only calling it when it will not lead to DoS.
Assessed type
Oracle
vonMangoldt (Wise Lending) commented:
It takes second highest out of last 50 rounds if you recalibrate. If it takes forever to update for chainlink it means there is no volatility. So dismissed.
Warden discussed a potential scenario when the Oracle would be considered dead after just one minute of inactivity.
vm06007 (Wise Lending) commented:
@Trust - it depends on the expected heartbeat, if it’s one minute, and latest data does not come within that frame then Oracle SHOULD be considered dead.
Example:
recalibrate()looks for second longest time gap between latest 50 (or 500 depending on chain) rounds, by analyzing timegaps between reported prices in last 50/500 rounds contract chooses appropriate expected timeframe when Oracle needs to answer before considered dead. If the time frame is too short this is only because that what was picked up from latest round data and should be honored (unlike this finding).Note that it can be recalibrated to increase the expected time if needed.
Mitigated here.
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
Likely the heartbeat is derived from the second-largest gap among the last 50 updates, which can be very short after a burst of updates, rather than using Chainlink's native heartbeat.
Impact
The oracle could be considered dead for a substantial time, blocking liquidations, deposits, withdrawals and other functions, potentially leading to bad debt or griefing; the report notes this can be worse with block stuffing or high gas prices.
What the attacker needed
Ability to call recalibrate (no access control); a period of frequent Chainlink updates; a subsequent quiet period
The fix
The project mitigated the issue in a later commit, and the report recommends using Chainlink's native heartbeat and adding access control to recalibrate.
How it was found
- Call recalibrate on a token whose last 50 Chainlink updates were frequent, setting a short heartbeat.
- Wait for a period with no Chainlink updates longer than that short heartbeat.
- Observe that the oracle is considered dead and functions using it revert.
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 blockchain oracle is a service that feeds outside data, like prices, into a smart contract. This project checks whether the oracle has updated recently enough; if not, it treats the oracle as broken and blocks actions. The bug is that the 'recently enough' threshold can be set too low after a busy period, so the oracle is wrongly treated as broken during normal quiet times.
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.