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
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
- Add
strict_majority(n)helper returning(n / 2) + 1- Replace
div_ceil(2)inreconstruct_rik_dataandreconstruct_recovery_key
Status: Mitigation confirmed. Full details in reports from montecristo, niffylord, and DCENT09.
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.