Skip to content
Smart contracts Audit finding Beginner

Market.set_pyth_contract_id should emit an event

The market contract's function that updates the Pyth oracle contract identifier writes the new value to storage without emitting an event. As a result, off-chain observers would not be notified when this important configuration changes.

jasonxiale Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#35768 [SC-Insight] `Market.set_pyth_contract_id` should emit an event

Submitted on Oct 7th 2024 at 09:43:53 UTC by @jasonxiale for IOP | Swaylend

Description

Brief/Intro

While changing the system configuration, an event should be emitted. `Market.set_pyth_contract_id` is used to change `Pyth contract`. Because Pyth is an important factor in the system, so an event should be emitted.

Vulnerability Details

As shown in the following code, there is not event emitted ```Rust 941 // # 10. Pyth Oracle management 942 #[storage(write)] 943 fn set_pyth_contract_id(contract_id: ContractId) { 944 // Only owner can set the Pyth contract ID 945 only_owner(); 946 storage.pyth_contract_id.write(contract_id); <<<--- event should be emitted 947 } ```

Impact Details

Information about the Pyth is changed will be missing.

References

Add any relevant links to documentation or code

Proof of Concept

Proof of Concept

As shown in the following code, there is not event emitted ```Rust 941 // # 10. Pyth Oracle management 942 #[storage(write)] 943 fn set_pyth_contract_id(contract_id: ContractId) { 944 // Only owner can set the Pyth contract ID 945 only_owner(); 946 storage.pyth_contract_id.write(contract_id); <<<--- event should be emitted 947 } ```

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 setter function was written to update storage but the developers omitted an event emission for this configuration change.

Impact

Information about changes to the Pyth contract identifier would be missing from event logs, so observers relying on events could miss the update.

What the attacker needed

Owner role on the market contract

The fix

The setter should emit an event recording the new Pyth contract identifier whenever it is changed.

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 can record a note, called an event, whenever something important changes, so that outside programs and users can see it. Here, the function that swaps which price oracle the contract trusts changes the stored value silently, with no note. That makes it harder to notice or audit the change from outside the blockchain.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.