Skip to content

Commit

Permalink
bridge: fix quorum (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikhofstadt authored Oct 25, 2020
1 parent c088219 commit 8d7a356
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ethereum/contracts/Wormhole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ contract Wormhole is ReentrancyGuard {
GuardianSet memory guardian_set = guardian_sets[vaa_guardian_set_index];
require(guardian_set.keys.length > 0, "invalid guardian set");
require(guardian_set.expiration_time == 0 || guardian_set.expiration_time > block.timestamp, "guardian set has expired");
require(((guardian_set.keys.length / 4) * 3) + 1 <= len_signers, "no quorum");
// For guardian sets < 3, the division by 3 evaluates to 0 and the quorum would not be calculated correctly
// We fall back to the guardian set size as quorum for < 3, because 2/3+ for <3 is always the set size
require((guardian_set.keys.length < 3 && len_signers == guardian_set.keys.length) || (len_signers >= 3 && ((guardian_set.keys.length / 3) * 2) + 1 <= len_signers), "no quorum");

int16 last_index = - 1;
for (uint i = 0; i < len_signers; i++) {
Expand Down
12 changes: 8 additions & 4 deletions solana/bridge/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,17 @@ impl Bridge {
return Err(ProgramError::InvalidAccountData);
}

// Check quorum
if (sig_state
let signature_count = (sig_state
.signatures
.iter()
.filter(|v| v.iter().filter(|v| **v != 0).count() != 0)
.count() as u8)
< (((guardian_set.len_keys / 4) * 3) + 1)
.count() as u8);
// Check quorum
// For guardian sets < 3, the division by 3 evaluates to 0 and the quorum would not be calculated correctly
// We fall back to the guardian set size as quorum for < 3, because 2/3+ for <3 is always the set size
if (guardian_set.len_keys < 3 && signature_count != guardian_set.len_keys)
|| (guardian_set.len_keys >= 3
&& signature_count < (((guardian_set.len_keys / 3) * 2) + 1))
{
return Err(ProgramError::InvalidArgument);
}
Expand Down

0 comments on commit 8d7a356

Please sign in to comment.