From 8d586d363ea1588613213cac5ee8933b7b461b5c Mon Sep 17 00:00:00 2001 From: Ludo Galabru Date: Thu, 7 Dec 2023 17:13:43 -0500 Subject: [PATCH] fix: compute quorum (vs hard code) --- contracts/wormhole/wormhole-core-v1.clar | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/wormhole/wormhole-core-v1.clar b/contracts/wormhole/wormhole-core-v1.clar index e7a235f..786d1f1 100644 --- a/contracts/wormhole/wormhole-core-v1.clar +++ b/contracts/wormhole/wormhole-core-v1.clar @@ -66,8 +66,6 @@ (define-constant ERR_GSU_CHECK_CHAIN (err u1303)) ;; Guardian Set Update new index invalid (define-constant ERR_GSU_CHECK_INDEX (err u1304)) -;; Quorum of addresses required -(define-constant QUORUM u13) (define-constant hk-cursor-v2 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-cursor-v2) @@ -176,7 +174,7 @@ (asserts! (is-eq (get version (get vaa message)) u1) ERR_VAA_CHECKS_VERSION_UNSUPPORTED) ;; Ensure that the count of valid signatures is >= 13 - (asserts! (>= (len (get result signatures-from-active-guardians)) QUORUM) + (asserts! (>= (len (get result signatures-from-active-guardians)) (get-quorum (len active-guardians))) ERR_VAA_CHECKS_THRESHOLD_SIGNATURE) ;; Good to go! (ok (get vaa message))))) @@ -357,6 +355,9 @@ } }))) +(define-private (get-quorum (guardian-set-size uint)) + (+ (/ (* guardian-set-size u2) u3) u1)) + (define-private (is-guardian-cue (byte (buff 1)) (acc { cursor: uint, result: (list 19 uint) })) (if (is-eq u0 (mod (get cursor acc) u20)) {