Corruption of oracle data
The StaderOracle contract stores price data in a shared array without separating it by reporting block, so data from different blocks gets mixed. When an older block is finalised, the newer block's data is lost, corrupting the oracle's price feed.
Submitted by etherhood
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/StaderOracle.sol#L270 https://github.com/code-423n4/2023-06-stader/blob/main/contracts/StaderOracle.sol#L285
Proof of Concept
Block for lastReportedSDPriceData = 7200
Let’s make the current block = 21601
Now StaderOracle will have data for 14400 and 21600, both blocks are being pushed by nodes and in the prices array.
It will be all mixed up. Also, As soon as the 14400 block is finalised, the data for block 21600 is all lost as well.
Recommended Mitigation Steps
Add if (_sdPriceData.reportingBlockNumber == getSDPriceReportableBlock()) to ensure it is always the latest reportable block data.
Add mapping(uint256 => uint256[]) blockPrices to store the prices array separately for each block being reported, to avoid mixing and corruption of data. Or have uint256 currentEpochBlock, so when a new block of data is pushed, previous data is deleted before pushing the new data.
if(_sdPriceData.reportingBlockNumber!=currentEpochBlock){
delete prices;
}
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 contract uses a single shared array for prices without keying it by reporting block, so submissions for different blocks overwrite or mix with each other.
Impact
The oracle's price data becomes corrupted and newer data can be lost, which could lead to incorrect price feeds being used by the protocol.
What the attacker needed
Oracle nodes submit price data; multiple reporting blocks occur
The fix
The contract should check that the reported block is the latest reportable block and store prices per block, or clear previous data before pushing new data.
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.
An oracle is a service that feeds outside data, like prices, into a blockchain. This contract kept all price reports in one list without tagging which block they belonged to, so reports from different times got jumbled together and older data could wipe out newer data.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.