Oracle data feed can be outdated yet used anyways which will impact payment logic
The price feed contract used only the price answer from Chainlink's latestRoundData() without checking whether the data was stale or from a complete round. An attacker could exploit outdated price data to cause incorrect token minting, distribution amounts, and overflow calculations, impacting all projects and token holders.
Submitted by 0xNineDec, also found by 0x1f8b, 0x29A, 0x52, 0xdanial, 0xDjango, 0xf15ers, bardamu, cccz, Cheeezzyyyy, Chom, codexploder, defsec, Franfran, Alex the Entreprenerd, Green, hake, hansfriese, horsefacts, hubble, hyh, IllIllI, jonatascm, kebabsec, Meera, oyc_109, pashov, rbserver, Ruhum, simon135, tabish, tintin, and zzzitron
Impact
The current implementation of JBChainlinkV3PriceFeed is used by the protocol to showcase how the feed will be retrieved via Chainlink Data Feeds. The feed is used to retrieve the currentPrice, which is also used afterwards by JBPrices.priceFor(), then by JBSingleTokenPaymentTerminalStore.recordPaymentFrom(), JBSingleTokenPaymentTerminalStore.recordDistributionFor, JBSingleTokenPaymentTerminalStore.recordUsedAllowanceOf, JBSingleTokenPaymentTerminalStore._overflowDuring and JBSingleTokenPaymentTerminalStore._currentTotalOverflowOf. Although the current feeds are calculated by a non implemented IJBPriceFeed, if the implementation of the price feed is the same as the showcased inJBChainlinkV3PriceFeed, the retrieved data can be outdated or out of bounds.
It is important to remember that the sponsor said on the dedicated Discord Channel that also oracle pricing and data retrieval is inside the scope.
Proof of Concept
Chainlink classifies their data feeds into four different groups regarding how reliable is each source thus, how risky they are. The groups are Verified Feeds, Monitored Feeds, Custom Feeds and Specialized Feeds (they can be seen here). The risk is the lowest on the first one and highest on the last one.
A strong reliance on the price feeds has to be also monitored as recommended on the Risk Mitigation section. There are several reasons why a data feed may fail such as unforeseen market events, volatile market conditions, degraded performance of infrastructure, chains, or networks, upstream data providers outage, malicious activities from third parties among others.
Chainlink recommends using their data feeds along with some controls to prevent mismatches with the retrieved data. Along some recommendations, the feed can include circuit breakers (for extreme price events), contract update delays (to ensure that the injected data into the protocol is fresh enough), manual kill-switches (to cease connection in case of found bug or vulnerability in an upstream contract), monitoring (control the deviation of the data) and soak testing (of the price feeds).
The feed.lastRoundData() interface parameters according to Chainlink are the following:
function latestRoundData() external view
returns (
uint80 roundId, // The round ID.
int256 answer, // The price.
uint256 startedAt, // Timestamp of when the round started.
uint256 updatedAt, // Timestamp of when the round was updated.
uint80 answeredInRound // The round ID of the round in which the answer was computed.
)
Regarding Juicebox itself, only the answer is used on the JBChainlinkV3PriceFeed.currentPrice() implementation. The retrieved price of the priceFeed can be outdated and used anyways as a valid data because no timestamp tolerance of the update source time is checked while storing the return parameters of feed.latestRoundData() inside JBChainlinkV3PriceFeed.currentPrice() as recommended by Chainlink in here. The usage of outdated data can impact on how the Payment terminals work regarding pricing calculation and value measurement.
Precisely the following protocol logic within JBSingleTokenPaymentTerminalStore will work unexpectedly regarding value management.
-
recordPaymentFrom():This function handles the minting of a project tokens according to a data source if one is given. If the retrieved value of the oracle is outdated, the
_weightRatioat Line 387 will return an incorrect value and then thetokenCountcalculated amount will suffer from this mismatch, impacting in the amount of tokens minted. -
recordDistributionFor():Performs the recording of recently distributed funds for a project. On line 580 the
distributedAmountis computed and if the boolean check is false, then the call will perform a call topriceForat line 585. If the returned oracle value is not adjusted with current market prices, thedistributedAmountwill also drag that error computing an incorrectdistributedAmount. Afterwards, because thedistributedAmountis also used to update the token balances of themsg.sender(line 598) it means that the mismatch impacts on the modified balance. -
recordUsedAllowanceOf():Keeps record of used allowances of a project. It returns are analogue to the ones shown at
recordDistributionForwhere theusedAmountresembles thedistributedAmount. TheusedAmountis also used to update the project’s balance. If the data of the oracle is outdated, theusedAmountwill be calculated dragging that error. -
_overflowDuring():Used to get the amount that is overflowing relative to a specified cycle. The data retrieved from the oracle is used to calculate the value of
_distributionLimitRemainingon line 827 which is used later to calculate the return value if the boolean check performed at line 834 is true. Because the return of this function is the current balance of a project minus the amount that can be still distributed, if the amount that can still be distributed is wrong so will be the subtraction thus the return value. -
_currentTotalOverflowOf():Similar to the latter but used to get the overflow of all the terminals of a project. If the retrieved data has a mismatch with the market, the
_totalOverflow18Decimalcalculated on line 866 if the boolean check is false will drag this mismatch which will also be dragged into the final return of the function.
The issues of those miscalculations impact on every project currently minted, which also affects subsequently on each user that has tokens of a project resulting in a high reach impact.
Recommended Mitigation Steps
As Chainlink recommends:
Your application should track the
latestTimestampvariable or use theupdatedAtvalue from thelatestRoundData()function to make sure that the latest answer is recent enough for your application to use it. If your application detects that the reported answer is not updated within the heartbeat or within time limits that you determine are acceptable for your application, pause operation or switch to an alternate operation mode while identifying the cause of the delay.During periods of low volatility, the heartbeat triggers updates to the latest answer. Some heartbeats are configured to last several hours, so your application should check the timestamp and verify that the latest answer is recent enough for your application.
It is recommended to add a tolerance that compares the updatedAt return timestamp from latestRoundData() with the current block timestamp and ensure that the priceFeed is being updated with the required frequency.
If the ETH/USD is the only one that is needed to retrieve, because it is the most popular and available pair. It can also be useful to add other oracle to get the price feed (such as Uniswap’s). This can be used as a redundancy in the case of having one oracle that returns outdated values (what is outdated and what is up to date can be determined by a tolerance as mentioned).
mejango (Juicebox) confirmed, but disagreed with severity and commented:
There is also a good description in this duplicate #78
mejango (Juicebox) resolved:
PR with fix: PR #1
berndartmueller (warden) reviewed mitigation:
Appropriate validations to prevent price staleness, round incompleteness and a negative price is put in place now.
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 price feed contract did not validate the updatedAt timestamp or round completeness from Chainlink's latestRoundData(), so stale or incomplete price data was accepted as valid.
Impact
If the price feed returns outdated data, token minting, distribution amounts, used allowances, and overflow calculations could be incorrect, affecting all projects and their token holders; the report notes the current feeds are not yet implemented but warns of the risk if the showcased implementation is used.
What the attacker needed
Price feed returns stale or incomplete data; protocol uses the showcased feed implementation
The fix
The fix was to add validations that prevent price staleness, round incompleteness, and negative prices, as confirmed by the reviewer.
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 feed is a service that gives a smart contract the current price of an asset, like ETH in USD. This contract trusted the price without checking how old it was, so if the feed stopped updating, the contract would keep using an old price. That could make the contract mint or distribute the wrong number of tokens.