NFTFloorOracle’s assets will use old prices if added back after removal
When an asset is removed from the NFTFloorOracle, its nested feederPrice mapping is not cleared, so if the asset is later re-added, old prices are reused if their timestamps are still within the expiration period. This can lead to incorrect NFT valuations and potentially the liquidation of healthy accounts.
Submitted by hyh, also found by Trust, SmartSek, and kaliberpoziomka8552
assetFeederMap mapping has elements of the FeederRegistrar structure type, that contains nested feederPrice mapping. When an asset is being removed with _removeAsset(), its assetFeederMap entry is deleted with the plain delete assetFeederMap[_asset] operation, which leaves feederPrice mapping intact.
This way if the asset be added back after removal its old prices will be reused via _combine() given that their timestamps are fresh enough and the corresponding feeders stay active.
Impact
Old prices can be irrelevant in the big enough share of cases. The asset can be removed due to its internal issues that are usually coupled with price disruptions, so it is reasonable to assume that recent prices of a removed asset can be corrupted for the same reason that caused its removal.
Nevertheless these prices will be used as if they were added for this asset after its return. Recency logic will work as usual, so the issue is conditional on config.expirationPeriod being substantial enough, which might be the case for all illiquid assets.
Net impact is incorrect valuation of the corresponding NFTs, that can lead to the liquidation of the healthy accounts, which is the permanent loss of the principal funds for their owners. However, due to prerequisites placing the severity to be medium.
Proof of Concept
_removeAsset() will delete the assetFeederMap entry, setting its elements to zero:
function _removeAsset(address _asset)
internal
onlyWhenAssetExisted(_asset)
{
uint8 assetIndex = assetFeederMap[_asset].index;
delete assets[assetIndex];
delete assetPriceMap[_asset];
delete assetFeederMap[_asset];
emit AssetRemoved(_asset);
}
Notice, that assetFeederMap is the mapping with FeederRegistrar elements:
/// @dev Original raw value to aggregate with
// the NFT contract address -> FeederRegistrar which contains price from each feeder
mapping(address => FeederRegistrar) public assetFeederMap;
FeederRegistrar is a structure with a nested feederPrice mapping.
feederPrice nested mapping will not be deleted with delete assetFeederMap[_asset]:
struct FeederRegistrar {
// if asset registered or not
bool registered;
// index in asset list
uint8 index;
// if asset paused,reject the price
bool paused;
// feeder -> PriceInformation
mapping(address => PriceInformation) feederPrice;
}
Per operation docs So if you delete a struct, it will reset all members that are not mappings and also recurse into the members unless they are mappings:
https://docs.soliditylang.org/en/latest/types.html#delete
This way, if the asset be added back its feederPrice mapping will be reused.
On addition of this old _asset only its assetFeederMap[_asset].index be renewed:
function _addAsset(address _asset)
internal
onlyWhenAssetNotExisted(_asset)
{
assetFeederMap[_asset].registered = true;
assets.push(_asset);
assetFeederMap[_asset].index = uint8(assets.length - 1);
emit AssetAdded(_asset);
}
This means that the old prices will be immediately used for price construction, given that config.expirationPeriod is big enough:
function _combine(address _asset, uint256 _twap)
internal
view
returns (bool, uint256)
{
FeederRegistrar storage feederRegistrar = assetFeederMap[_asset];
uint256 currentBlock = block.number;
//first time just use the feeding value
if (assetPriceMap[_asset].twap == 0) {
return (true, _twap);
}
//use memory here so allocate with maximum length
uint256 feederSize = feeders.length;
uint256[] memory validPriceList = new uint256[](feederSize);
uint256 validNum = 0;
//aggeregate with price from all feeders
for (uint256 i = 0; i < feederSize; i++) {
PriceInformation memory priceInfo = feederRegistrar.feederPrice[
feeders[i]
];
if (priceInfo.updatedAt > 0) {
uint256 diffBlock = currentBlock - priceInfo.updatedAt;
if (diffBlock <= config.expirationPeriod) {
validPriceList[validNum] = priceInfo.twap;
validNum++;
}
}
}
if (validNum < MIN_ORACLES_NUM) {
return (false, assetPriceMap[_asset].twap);
}
_quickSort(validPriceList, 0, int256(validNum - 1));
return (true, validPriceList[validNum / 2]);
}
Recommended Mitigation Steps
Consider clearing the current list of prices on asset removal, for example:
function _removeAsset(address _asset)
internal
onlyWhenAssetExisted(_asset)
{
+ FeederRegistrar storage feederRegistrar = assetFeederMap[_asset];
+ uint256 feederSize = feeders.length;
+ for (uint256 i = 0; i < feederSize; i++) {
+ delete feederRegistrar.feederPrice[feeders[i]];
+ }
uint8 assetIndex = feederRegistrar.index;
delete assets[assetIndex];
delete assetPriceMap[_asset];
delete assetFeederMap[_asset];
emit AssetRemoved(_asset);
}
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 delete operation on a struct containing a nested mapping does not clear the mapping's entries, so old price data persists after asset removal.
Impact
Incorrect valuation of NFTs could lead to liquidation of healthy accounts, causing permanent loss of principal funds, though the severity is medium due to prerequisites.
What the attacker needed
Asset removed then re-added; expirationPeriod large enough; feeders still active
The fix
The asset removal function should explicitly delete each feeder's price entry before deleting the assetFeederMap entry.
How it was found
- An asset is removed via _removeAsset(), which deletes the assetFeederMap entry but leaves the nested feederPrice mapping intact.
- The same asset is later added back via _addAsset(), which only sets the registered flag and index, leaving the old feederPrice data.
- When _combine() is called, it reads the old feederPrice entries and uses them if their timestamps are within the expiration period.
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.
This is about a smart contract that keeps track of NFT prices. When an asset is removed, the contract deletes some data but forgets to delete the stored prices from individual feeders. If the asset is added back later, those old prices are still there and might be used again, even though they could be wrong.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.