Skip to content
Business logic Audit finding Intermediate

Market.update_collateral_asset should reuse old configuration's asset_id

The update_collateral_asset function stores the caller-supplied configuration without forcing its asset_id to match the key it is stored under, unlike update_market_configuration which reuses the old base_token. An owner could therefore save a configuration whose asset_id disagrees with its storage key, leaving inconsistent collateral data.

jasonxiale Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#36138 [SC-Insight] `Market.update_collateral_asset` should reuse old configuration's `asset_id`

Submitted on Oct 21st 2024 at 15:32:58 UTC by @jasonxiale for IOP | Swaylend

Description

Brief/Intro

In Market.update_market_configuration, while updating market configuration, the old `base_token` is reused in main.sw#L1307

The same rule should apply to Market.update_collateral_asset, while updating CollateralConfiguration, `CollateralConfiguration.asset_id` should be reused.

Vulnerability Details

As the following code shows, while updating CollateralConfiguration, the function doesn't reuse old `CollateralConfiguration.asset_id` ```Rust 262 #[storage(write)] 263 fn update_collateral_asset(asset_id: AssetId, configuration: CollateralConfiguration) { 264 // Only owner can update collateral asset 265 only_owner(); 266 267 // Check if asset exists 268 require( 269 storage 270 .collateral_configurations 271 .get(asset_id) 272 .try_read() 273 .is_some(), 274 Error::UnknownAsset, 275 ); 276 277 storage 278 .collateral_configurations 279 .insert(asset_id, configuration); 280 281 log(CollateralAssetUpdated { 282 asset_id, 283 configuration, 284 }); 285 } ```

Impact Details

avoid mistake

References

Add any relevant links to documentation or code

Proof of Concept

Proof of Concept

As the following code shows, while updating CollateralConfiguration, the function doesn't reuse old `CollateralConfiguration.asset_id` ```Rust 262 #[storage(write)] 263 fn update_collateral_asset(asset_id: AssetId, configuration: CollateralConfiguration) { 264 // Only owner can update collateral asset 265 only_owner(); 266 267 // Check if asset exists 268 require( 269 storage 270 .collateral_configurations 271 .get(asset_id) 272 .try_read() 273 .is_some(), 274 Error::UnknownAsset, 275 ); 276 277 storage 278 .collateral_configurations 279 .insert(asset_id, configuration); 280 281 log(CollateralAssetUpdated { 282 asset_id, 283 configuration, 284 }); 285 } ```

The original report as published on Immunefi, by jasonxiale. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

Impact

The contract may hold inconsistent collateral configuration data, which the report frames as avoiding mistakes rather than a direct loss of funds.

What the attacker needed

Owner privileges

The fix

The update function should reuse the old configuration's asset_id, as update_market_configuration does with base_token.

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 smart contract keeps a table of collateral assets, each stored under an identifier. When the owner updates an entry, the code saves whatever identifier is inside the new settings instead of keeping the one the entry was stored under. That can leave the table saying one thing and the settings saying another, which is confusing and could cause mistakes later.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by jasonxiale

View all

25 more disclosed reports, best first.

More from Swaylend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.