Expiration vector length mismatch causes panic in extend_ttl() when assets are added with zero initial expiration period
The oracle contract maintains two parallel vectors, asset_list and expiration, which must stay the same length. When assets are added with a zero initial expiration period, no expiration record is created, so later calls to extend_ttl() panic with an index out of bounds error.
Submitted by piki, also found by 0xgeeee, 0xnija, 0xvd, Angry_Mustache_Man, Bala1796, CowBoy, cy97, HUNTERRRRRRR, jectaw, jsmaxi, KKKKK, klau5, Mahmud, Manosh19, newspacexyz, niffylord, nstatoshi, OhmOudits, oxwhite, Petrus, rare_one, shaflow2, sl1, and sudais_b
assets.rs#L54-L80assets.rs#L109-L161lib.rs#L362-L364assets.rs#L93-L106
Finding description
The oracle contract maintains two parallel vectors: asset_list (all assets) and expiration (expiration timestamps). These vectors must always have the same length because extend_ttl() uses asset indices to access expiration records. However, a bug in add_assets() allows assets to be added without corresponding expiration records, breaking this invariant and causing extend_ttl() to panic.
The core problem: When add_assets() is called with initial_expiration_period == 0, the function adds the asset to asset_list but skips adding an expiration record to the expiration vector. This happens because of a conditional check that only creates expiration records when both the fee config is set AND the expiration timestamp is greater than zero.
Here’s what happens step by step:
-
Asset addition (line 68): The asset is unconditionally added to
asset_listviaasset_list.push_back(asset). -
Expiration record creation (lines 70-72): The code checks:
if is_fee_config_set && expiration_timestamp > 0 { expiration.push_back(expiration_timestamp); } -
The mismatch: When
initial_expiration_period == 0:get_expiration_timestamp()returns0(line 17).- The condition
is_fee_config_set && expiration_timestamp > 0evaluates to false. - Asset is added but NO expiration record is created.
- Result:
asset_list.len() == Nbutexpiration.len() == N-1.
Why This breaks extend_ttl(): The extend_ttl() function assumes both vectors are in sync.
When it tries to update an expiration record:
-
It resolves the asset index from the asset list (line 121-125).
-
Loads the expiration vector (line 146).
-
Attempts to get the current expiration:
expiration.get(asset_index)(line 148-150).- This returns
Noneif the index is out of bounds, but the code handles this withunwrap_or_else.
- This returns
-
The crash happens in (line 158):
expiration.set(asset_index, asset_expiration).- Soroban’s
Vec::set()panics withIndexBoundserror whenasset_index >= expiration.len(). - The error message confirms:
"object index out of bounds".
- Soroban’s
Real-world scenario: The Beam contract specifically calls add_assets() with initial_expiration_period == 0 (see beam-contract/src/lib.rs:363). This means every time an admin adds assets through the Beam contract after setting a fee config, those assets are added without expiration records. When users try to extend the TTL for these assets by burning tokens, the transaction panics and fails.
Why init_expiration_config() doesn’t fix it: The init_expiration_config() function seems like it should repair mismatches, but it has an early return check (line 95-96):
if expiration_records.len() > 0 {
return; // expiration values for existing price feeds already initialized
}
This means if ANY expiration records exist (even if incomplete), the function returns immediately without checking if the vectors are actually synchronized. So if you have 3 assets but only 2 expiration records, init_expiration_config() won’t fix the mismatch.
Impact
- Functionality breakage: Users cannot extend TTL for assets added via Beam contract’s
add_assets(). This breaks a core feature where sponsors burn tokens to keep price feeds alive. - No work-around: There’s no way for users to fix this themselves. The admin would need to remove and re-add assets with a non-zero expiration period, but this isn’t practical and may not be possible depending on contract state.
- Production risk: This affects all assets added after fee config is set via Beam contract. In a production deployment, this could affect multiple assets and make them unusable for TTL extension.
- Silent failure: The bug only manifests when someone tries to extend TTL. Assets can be added successfully, queries work fine, but the TTL extension feature is completely broken for those assets.
Attack Surface: While this isn’t directly exploitable by attackers (it requires admin actions), it creates a situation where:
- Admin adds assets thinking everything is fine.
- Users try to sponsor price feeds by extending TTL.
- Transactions fail, potentially causing confusion and loss of funds (if gas/fees are charged).
- Price feeds may expire unexpectedly if TTL cannot be extended.
Recommended mitigation steps
The fix needs to ensure both vectors stay synchronized. Here are the recommended approaches:
Option 1: Always create expiration records when fee config is set. (Recommended)
Modify add_assets() to always create expiration records when fee config is set, even if initial_expiration_period == 0:
pub fn add_assets(e: &Env, assets: Vec<Asset>, initial_expiration_period: u32) {
let expiration_timestamp = get_expiration_timestamp(e, initial_expiration_period);
let mut asset_list = load_all_assets(e);
let mut expiration = load_expiration_records(e);
let is_fee_config_set = settings::get_fee_config(e) != FeeConfig::None;
for asset in assets.iter() {
if resolve_asset_index(e, &asset).is_some() {
panic_with_error!(&e, Error::AssetAlreadyExists);
}
set_asset_index(e, &asset, asset_list.len());
asset_list.push_back(asset);
// FIX: Always create expiration record when fee config is set
if is_fee_config_set {
// Use expiration_timestamp if > 0, otherwise use current time + initial_expiration_period
let exp_time = if expiration_timestamp > 0 {
expiration_timestamp
} else {
timestamps::ledger_timestamp(&e) + timestamps::days_to_milliseconds(initial_expiration_period)
};
expiration.push_back(exp_time);
}
}
// ... rest of function
}
Option 2: Add defensive check in extend_ttl().
Extend the vector if needed before setting:
// In extend_ttl(), before line 158:
let mut expiration = load_expiration_records(e);
let all_assets = load_all_assets(e);
// Ensure expiration vector has enough capacity
while expiration.len() <= asset_index {
expiration.push_back(0); // or appropriate default
}
expiration.set(asset_index, asset_expiration);
Option 3: Fix init_expiration_config() to repair mismatches.
Remove the early return and always ensure vectors are synchronized:
pub fn init_expiration_config(e: &Env, initial_expiration_period: u32) {
let mut expiration_records = load_expiration_records(e);
let assets = load_all_assets(e);
let exp = get_expiration_timestamp(e, initial_expiration_period);
// FIX: Always sync vectors, don't early return
// Extend expiration records if needed
while expiration_records.len() < assets.len() {
expiration_records.push_back(exp);
}
set_expirations_records(e, &expiration_records);
}
Proof of Concept
Copy-paste PoC (drop-in test)
View detailed Proof of Concept
Expected test output: When running poc_expiration_vector_mismatch_panic, you should see:
thread 'tests::poc_expiration_vector_mismatch_panic' panicked at .../host.rs:861:9:
HostError: Error(Object, IndexBounds)
Event log shows:
"object index out of bounds", 10
This confirms that expiration.set() panics when the index is out of bounds, proving the vector mismatch bug exists and causes real failures in production scenarios.
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 conditional check in add_assets() only creates an expiration record when the fee config is set and the expiration timestamp is greater than zero, so a zero initial expiration period skips record creation and breaks the one-to-one mapping.
Impact
Users cannot extend the TTL for affected assets, breaking a core feature and potentially causing price feeds to expire unexpectedly; the issue requires admin action to add assets with zero expiration and is not directly exploitable by attackers.
What the attacker needed
Admin adds assets with zero expiration; fee config is set
The fix
The fix should ensure both vectors stay synchronized, for example by always creating an expiration record when the fee config is set, or by adding a defensive check in extend_ttl().
How it was found
- Call add_assets() with initial_expiration_period set to zero.
- The asset is added to asset_list but no expiration record is created.
- Later, call extend_ttl() for that asset.
- The code attempts to set the expiration at the asset's index, which is out of bounds, causing a panic.
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.
The contract keeps two lists: one of assets and one of their expiration times. They are supposed to be the same length. A mistake lets an asset be added without an expiration time, so when someone later tries to update the expiration, the code looks for an entry that isn't there and crashes.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.