Skip to content

Commit ba86e0b

Browse files
Merge pull request #149 from mochimodev/audit-fixes
Audit fixes: F-09 deterministic quorum assembly
2 parents ddcc829 + e345364 commit ba86e0b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/network.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -980,22 +980,26 @@ int scan_quorum
980980
/* check peer's chain weight against highweight */
981981
result = cmp256(node.tx.weight, highweight);
982982
if (result >= 0) {
983-
/* higher or same chain detected */
984-
if (result > 0) {
985-
/* higher chain detected */
986-
pdebug("new highweight");
983+
/* new best chain: strictly higher weight, OR equal weight
984+
* with numerically higher block hash (deterministic
985+
* tiebreaker to ensure quorum members share a single chain,
986+
* regardless of peer scan order) */
987+
if (result > 0 ||
988+
memcmp(node.tx.cblockhash, highhash, HASHLEN) > 0) {
989+
pdebug("new high chain");
987990
memcpy(highhash, node.tx.cblockhash, HASHLEN);
988991
memcpy(highweight, node.tx.weight, 32);
989992
put64(highbnum, node.tx.cblock);
990993
qcount = 0;
991994
if (quorum) {
992995
memset(quorum, 0, qlen * sizeof(word32));
993-
pdebug("higher chain found, quourum reset...");
996+
pdebug("new high chain found, quorum reset...");
994997
}
995998
}
996-
/* check block hash and add to quorum */
997-
if (memcmp(node.tx.cblockhash, highhash, HASHLEN) >= 0) {
998-
/* add ip to quorum, or q consensus */
999+
/* add ip to quorum only if it shares the exact high chain
1000+
* hash -- peers on different chains of equal weight must
1001+
* not be combined into a single quorum */
1002+
if (memcmp(node.tx.cblockhash, highhash, HASHLEN) == 0) {
9991003
if (quorum && qcount < qlen) {
10001004
quorum[qcount++] = peer;
10011005
pdebug("%s qualified", ntoa(&peer, NULL));

0 commit comments

Comments
 (0)