Skip to content
DoS Audit finding Intermediate

Unbounded associations per account make recovery initiation linear-time

Recovery associations are stored in an unbounded vector, and every recovery initiation and verification scans the entire list. An attacker with the signing key could add many associations, causing high latency, timeouts, or resource exhaustion.

johnyfwesh Follow with 0xcb90f054, DCENT09 and 2 others

Originally disclosed on Code4rena

Submitted by johnyfwesh, also found by 0xcb90f054, DCENT09, legendweb3, and wuji

lib/src/account/v0.rs #L100-L106

Recovery associations are stored in an unbounded Vec and every recovery initiation scans that entire list. RecoveryStateV0 carries all associations in assoc: Vec<AssociationsV0> with no cap or pagination (lib/src/account/v0.rs:100-106). AccountSecrets::add_association appends a new entry on each call without limits or rate controls (lib/src/account/v0.rs:605-619).

When recovery is initiated, AccountStateV0::initiate_recovery iterates over self.rec.assoc and attempts a symmetric decrypt against every stored association until one matches (lib/src/account/v0.rs:171-226). Recovery updates are also verified by linearly scanning rec.assoc and checking signatures (lib/src/account/v0.rs:786-833).

Because there is no bound or indexing structure, recovery initiation and verification remain in the number of associations, and n is fully controllable by the account owner (or any party with the signing key) via repeated add_association calls.

Affected Code

// lib/src/account/v0.rs:100-106
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct RecoveryStateV0 {
    pub pke: Option<pke::EncryptionKey>, // this is set iff. recovery has been started
    pub(crate) assoc: Vec<AssociationsV0>, // encryption of the recovery authorization key
    pub(crate) social: BackupCiphertext, // social backup ciphertext
    pub(crate) enc_msk: sym::AEADCiphertext, // encrypted MSK (encrypted with key derived from RIK and social shares)
}
  • All associations are kept in an unbounded Vec, so subsequent consumers must linearly scan the list.
// lib/src/account/v0.rs:605-619
pub fn add_association<R: Rng + CryptoRng>(
    &mut self,
    rng: &mut R,
) -> Result<RecoveryInitiationKey> {
    self.dirty = true;

    // generate fresh RIK for this association
    let rik = RecoveryInitiationKey::gen(rng);

    // Add to existing associations
    self.recovery
        .assoc
        .push(AssociationSecretV0 { rik: rik.clone() });
    Ok(rik)
}
  • Association addition simply pushes into the vector with no limit, deduplication, or guardrails.
// lib/src/account/v0.rs:171-226
pub fn initiate_recovery<R: Rng + CryptoRng>(
    &self,
    rng: &mut R,
    acc: AccountId,
    rik: &RecoveryInitiationKey,
) -> Result<(AccountUpdate, RecoverySecrets)> {
    // decrypt AssociationsV0 using RIK
    let encap = self
        .rec
        .assoc
        .iter()
        .find_map(|assoc| {
            // attempt to decrypt the encapsulated key using RIK
            let encap = sym::open::<EncapV0, _>(rik.as_bytes(), &assoc.encap, &acc).ok()?;

            // check if the verification key matches the expected one
            if encap.key_sig.verification_key() != assoc.sig {
                None
            } else {
                Some(encap)
            }
        })
        .ok_or(SwafeError::InvalidRecoveryKey)?;
    // ...
}
  • Each initiation attempt decrypts every stored association until it finds a match, making the runtime linear in the number of associations.
// lib/src/account/v0.rs:786-833
pub(super) fn verify_update(self, old: &AccountStateV0) -> Result<AccountStateV0> {
    match self.msg {
        AccountMessageV0::Recovery(recovery) => {
            let mut new_state = old.clone();
            {
                let rec = &mut new_state.rec;
                // ...
                for assoc in &rec.assoc {
                    // Verify signature using the recovery signing key from associations
                    if assoc.sig.verify(&recovery.sig, &recovery_msg).is_ok() {
                        verified = true;
                        break;
                    }
                }
                if !verified {
                    return Err(SwafeError::InvalidSignature);
                }
                // Set the recovery PKE to indicate recovery has been initiated
                rec.pke = Some(recovery.pke);
            }
            Ok(new_state)
        }
        // ...
    }
}
  • Recovery updates are also verified by iterating over the entire association list, compounding the per-operation cost as the vector grows.

Impact

  • Recovery initiation and verification perform decryptions/signature checks per attempt, so accounts with many associations can trigger high latency, timeouts, or resource exhaustion in constrained or multi-tenant environments.
  • Large association vectors also inflate persisted account state, increasing storage and serialization/deserialization overhead for all operations involving that account.

View detailed Proof of Concept

Recommended Mitigation

  • Enforce an upper bound or quota on associations per account (reject additions beyond the cap, or require revocation/rotation).
  • Replace the linear scan with keyed lookup (e.g., index by verification key or association identifier) or require callers to specify which association they intend to use, validated against stored metadata.
  • Add pagination or rate limiting around recovery initiation to prevent excessive per-request work, and prune or deduplicate stale associations during updates.

References

Swafe mitigated:

  • Add MAX_ASSOCIATIONS = 16 constant
  • add_association rejects at cap with TooManyAssociations
  • verify_allocation and verify_update reject submitted states exceeding cap
  • Contract error mapping for new variant

Status: Mitigation confirmed. Full details in reports from montecristo, niffylord, and DCENT09.


The original report as published on Code4rena, by johnyfwesh. 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 recovery association list is an unbounded vector, and recovery operations linearly scan it without any cap or indexing.

Impact

Accounts with many associations could experience high latency, timeouts, or resource exhaustion in constrained or multi-tenant environments, and large vectors inflate storage and serialization overhead.

What the attacker needed

Control of the account signing key; ability to call add_association repeatedly

The fix

The issue was mitigated by adding a maximum associations constant, rejecting additions beyond the cap, and validating submitted states against the 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.

This is a smart contract that manages account recovery. The code keeps a list of recovery keys, and every time someone starts recovery, it checks each key one by one. Because the list has no size limit, someone could add a huge number of keys, making each recovery check very slow and potentially causing the system to time out.

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.

More by johnyfwesh

View all

8 more disclosed reports, best first.

More from Swafe

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.