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.
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.
- Fee Calculation: The
beam-contract’scharge_invocation_feefunction calculates the service fee based directly on therecordsparameter provided by the user. The fee scales with the number of requested records. - Data Retrieval: When the
beam-contractcalls theoracleto fetch the historical price data, theoracle’sload_pricesfunction silently caps therecordsparameter 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
recordsvalues 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
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.