From eb3550ad397dc6d08f9c5947d68aa75828269ae7 Mon Sep 17 00:00:00 2001 From: Asa Oines Date: Thu, 5 Jan 2023 13:08:25 -0500 Subject: [PATCH] Protect against underflow in relayer (#1508) --- rust/hyperlane-base/src/types/multisig.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/hyperlane-base/src/types/multisig.rs b/rust/hyperlane-base/src/types/multisig.rs index 2f3e2b4b58..ee08f548af 100644 --- a/rust/hyperlane-base/src/types/multisig.rs +++ b/rust/hyperlane-base/src/types/multisig.rs @@ -62,14 +62,16 @@ impl MultisigCheckpointSyncer { // The highest viable checkpoint index is the minimum of the highest index // we (supposedly) have a quorum for, and the maximum index for which we can // generate a proof. - let mut index = std::cmp::min(*highest_quorum_index, maximum_index); - while index >= minimum_index { + let start_index = highest_quorum_index.min(&maximum_index); + if minimum_index > *start_index { + return Ok(None); + } + for index in (minimum_index..=*start_index).rev() { if let Ok(Some(checkpoint)) = self.fetch_checkpoint(index, validators, threshold).await { return Ok(Some(checkpoint)); } - index -= 1; } } Ok(None)