Skip to content
Business logic Audit finding Beginner

Systematic overcharge in prices and x_prices : Fee charged for requested records while return is capped at 20

The beam-contract charges a fee based on the number of records requested, but the oracle silently caps the returned records at 20. A user requesting more than 20 records pays for the full amount but receives only 20, causing an overcharge.

ht111111 Follow with 0xdaxn, 0xgeeee and 37 others

Originally disclosed on Code4rena

Submitted by ht111111, also found by 0xdaxn, 0xgeeee, 0xnija, 0xpetern, 0xvd, AllTooWell, arturtoros, axelot, ayden, cd_pandora, CoMMaNDO, CowBoy, dmdg321, edoscoba, HalalAudits, Ibukun, inh3l, johnyfwesh, JustUzair, KKKKK, manaalwk, Manosh19, max10afternoon, merlin, mrdafidi, mrFreedom, NexusAudits, niffylord, OhmOudits, psyone, rare_one, shaflow2, shieldrey, sl1, soloking, teoslaf, wafflewizard, y4y, and zcai

Finding description

The root cause of the vulnerability is a mismatch between the fee calculation logic in the beam-contract and the data retrieval logic in the underlying oracle contract for the prices and x_prices functions.

  1. Fee Calculation: The beam-contract’s charge_invocation_fee function calculates the service fee based directly on the records parameter provided by the user. The fee scales with the number of requested records.
  2. Data Retrieval: When the beam-contract calls the oracle to fetch the historical price data, the oracle’s load_prices function silently caps the records parameter to a maximum of 20. Any request for more than 20 records will only return 20, without any error or notification to the caller.

This creates a situation where for example, a user can request 50 records and be charged a fee calculated for 50 records, but only receive 20 records in return. The discrepancy between the number of records paid for and the number of records received constitutes a systemic overcharging vulnerability.

Impact

The primary impact is a direct and irrecoverable loss of user funds. Users who call prices or x_prices with a records value greater than 20 are systematically overcharged. The excess fees paid are burned, meaning they cannot be recovered.

  • Scaling Financial Loss: The magnitude of the overcharge increases linearly with the number of requested records. As demonstrated in the POC, requesting 100 records results in being overcharged by 333.3%, paying more than four times the fair price for the data received.
  • Hidden Bug: The vulnerability is non-reverting and silent. Users receive a successful response with 20 data points and may not notice the discrepancy unless they carefully audit their token balance against the expected cost for the data they actually received.
  • Potential for Exploitation: A malicious front-end could intentionally use high records values in its calls to the contract, causing users to burn excessive amounts of their tokens without their knowledge.

Recommended mitigation steps

To mitigate this vulnerability, the fee calculation should be synchronized with the actual number of records returned by the oracle. The most direct and least disruptive fix is to apply the same cap in the beam-contract before calculating the fee.

In beam-contract/src/lib.rs, modify the prices and x_prices functions to cap the records parameter at 20 before passing it to charge_invocation_fee.

Example for the prices function:

:206:210:beam-contract/src/lib.rs
// ... existing code ...
pub fn prices(e: &Env, caller: Address, asset: Asset, records: u32) -> Option<Vec<PriceData>> {
    caller.require_auth();

    // Mitigated fee charge
    let records_to_charge = records.min(20);
    charge_invocation_fee(e, &caller, InvocationComplexity::Price, records_to_charge);

    PriceOracleContractBase::prices(e, asset, records)
}
// ... existing code ...

By changing charge_invocation_fee(e, &caller, InvocationComplexity::Price, records); to use records.min(20), the fee charged will accurately reflect the maximum number of data points the user can receive, eliminating the overcharge issue. The same logic should be applied to the x_prices function.

Proof of Concept

View detailed Proof of Concept


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

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 fee calculation in the beam-contract uses the raw requested record count, while the oracle caps the returned records at 20, so the two are not synchronised.

Impact

Users who request more than 20 records are overcharged, and the excess fees are burned and cannot be recovered; a malicious front-end could exploit this to burn users' tokens.

What the attacker needed

Call prices or x_prices with records > 20

The fix

The fee calculation should cap the records parameter at 20 before charging, matching the oracle's cap.

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.

When you ask the service for price history, you say how many records you want and pay a fee based on that number. But the service only ever gives back 20 records, no matter how many you asked for. So if you ask for more than 20, you pay extra for data you never get.

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 ht111111

View all

3 more disclosed reports, best first.

More from Reflector V3

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.