Skip to content
Business logic Audit finding Intermediate

Majority consensus threshold not enforced for even number of nodes

The majority threshold calculation used ceiling division, so with an even number of nodes exactly half could meet the threshold instead of a true majority. This allowed a minority of nodes to control reconstruction of the RIK data and recovery key.

Tigerfrake Follow with 0xozovehe, AlexNik777 and 21 others

Originally disclosed on Code4rena

Submitted by Tigerfrake, also found by 0xozovehe, AlexNik777, arunabha003, blockace, bunnyhunter, cpsec, Evo, jerry0422, johnyfwesh, Khan2018, legendweb3, Meks079, odeili, pashap9990, SanketKogekar, securehash1, ShadowBytes, Silvermist, tradingview, XOMA, ZanyBonzy, zubyoz, and zzebra83

  • lib/src/association/v0.rs #L473
  • lib/src/association/v0.rs #L556

The AssociationV0::reconstruct_rik_data() and AssociationV0::reconstruct_recovery_key() functions uses div_ceil(2) for majority threshold calculation, which creates a vulnerability when dealing with even numbers of nodes.

    // Do a threshold vote on the fixed fields (same logic as reconstruct_msk)
    let mut votes = HashMap::new();
    for (_, record) in &v0_records {
        *votes.entry(record.fixed.clone()).or_insert(0) += 1;
    }

    //@audit-issue Less for even number of records
>>  let majority_threshold = v0_records.len().div_ceil(2);
    let majority_fixed = votes
        .into_iter()
        .find(|(_, count)| *count >= majority_threshold)
        .map(|(fixed, _)| fixed)
        .ok_or_else(|| {
            SwafeError::InvalidInput(
                "No majority consensus on fixed fields among MSK records".to_string(),
            )
        })?;

This allows a minority of nodes (exactly 50%) to control the reconstruction process instead of requiring a true majority (50% + 1). This undermines the core security guarantees of the threshold cryptography system. e.g:

// Flawed threshold calculation:
let majority_threshold = v0_records.len().div_ceil(2);

// For odd numbers:
// - 3 nodes: threshold = 2 (correct)

// For even numbers:
// - 4 nodes → threshold = 2 (50%, not majority)

Recommended mitigation steps

    // FIX: Use proper majority threshold (more than 50%)
-   let majority_threshold = v0_records.len().div_ceil(2);
+   let majority_threshold = (v0_records.len() / 2) + 1;

View detailed Proof of Concept

Swafe mitigated:

  • Add strict_majority(n) helper returning (n / 2) + 1
  • Replace div_ceil(2) in reconstruct_rik_data and reconstruct_recovery_key

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


The original report as published on Code4rena, by Tigerfrake. 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 threshold was computed with ceiling division, which for even counts yields exactly half rather than a strict majority.

Impact

A minority of nodes could control reconstruction of the RIK data and recovery key, undermining the threshold cryptography guarantees.

What the attacker needed

Even number of nodes; control of half the nodes

The fix

The threshold should be changed to strict majority, and the project mitigated it by adding a helper returning half plus one and replacing the ceiling division in both functions.

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.

In a system where several nodes must agree before a secret is rebuilt, you normally need more than half to agree. The code used a rounding-up division that, for an even number of nodes, let exactly half agree and still pass. That means a smaller group than intended could push through its version of the data.

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 Tigerfrake

View all

4 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.

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.