Skip to content
Business logic Audit finding Intermediate

Market.update_market_configuration should reuse old configuration's base_token.decimals

The update_market_configuration function preserves the original base_token but does not preserve base_token_decimals, so an owner could accidentally change the decimals of the base token. This could lead to incorrect calculations or accounting if the decimals are altered.

jasonxiale Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#36065 [SC-Insight] `Market.update_market_configuration` should reuse old configuration's `base_toke

Submitted on Oct 17th 2024 at 16:05:55 UTC by @jasonxiale for IOP | Swaylend

Description

Brief/Intro

In Market.update_market_configuration, while updating the `MarketConfiguration`, orignal `configuration.base_token` can't be changed in main.sw#L980, `MarketConfiguration.base_token_decimals` shouldn't be changed too.

Vulnerability Details

```Rust 971 // # 11. Changing market configuration 972 #[storage(write)] 973 fn update_market_configuration(configuration: MarketConfiguration) { 974 // Only owner can update the market configuration 975 only_owner(); 976 977 let mut configuration = configuration; 978 979 // Cannot change base token and tracking index scale 980 configuration.base_token = storage.market_configuration.read().base_token; <<<--- `MarketConfiguration.base_token_decimals` should be reused here too 981 configuration.base_tracking_index_scale = storage.market_configuration.read().base_tracking_index_scale; 982 983 // Update the market configuration 984 storage.market_configuration.write(configuration); 985 986 // Emit market configuration event
987 log(MarketConfigurationEvent { 988 market_config: configuration, 989 }); 990 } ```

Impact Details

To avoid the mistake

References

Add any relevant links to documentation or code

Link to Proof of Concept

https://gist.github.com/crazy4linux/382b80b244a219346a827755a3ea594e

Proof of Concept

Proof of Concept

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

Root cause

Likely the update function only overwrites base_token and base_tracking_index_scale from storage, omitting base_token_decimals, so the new configuration's decimals are accepted.

Impact

If the owner updates the configuration with different decimals, the market could use an incorrect decimal value, potentially causing miscalculations, but the report only states this as a precaution.

What the attacker needed

Owner calls update_market_configuration

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 stores settings for a market, including which token is the base token and how many decimal places that token uses. When the owner updates the settings, the code keeps the old base token but forgets to keep the old decimal count, so the decimals could be changed by mistake. This might cause the contract to misread amounts.

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.