From 851d165b7cb118b1a11b93afe725f9f2f2875c5f Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Wed, 29 Nov 2023 20:49:58 +0200 Subject: [PATCH] fix overflow --- .../core/src/proof_of_work/monero_rx/merkle_tree.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs b/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs index e56790cda7..9eaeede7b7 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs @@ -147,7 +147,7 @@ impl BorshDeserialize for MerkleProof { fn deserialize_reader(reader: &mut R) -> Result where R: io::Read { let len = reader.read_varint()?; - if len > MAX_MERKLE_TREE_PROOF_SIZE { + if len >= MAX_MERKLE_TREE_PROOF_SIZE { return Err(io::Error::new( io::ErrorKind::InvalidInput, "Larger than max merkle tree length".to_string(), @@ -167,7 +167,7 @@ impl BorshDeserialize for MerkleProof { impl MerkleProof { fn try_construct(branch: Vec, path_bitmap: u32) -> Option { - if branch.len() > MAX_MERKLE_TREE_PROOF_SIZE { + if branch.len() >= MAX_MERKLE_TREE_PROOF_SIZE { return None; } Some(Self { branch, path_bitmap }) @@ -350,7 +350,7 @@ mod test { let hashes = create_monero_hashes(input_vec); let length = hashes.len(); let res = MerkleProof::try_construct(hashes, path); - if length > MAX_MERKLE_TREE_PROOF_SIZE { + if length >= MAX_MERKLE_TREE_PROOF_SIZE { return res.is_none(); } res.is_some() @@ -367,7 +367,7 @@ mod test { let hashes = create_monero_hashes(input_vec); let hash = hashes[0]; let length = hashes.len(); - if length > MAX_MERKLE_TREE_PROOF_SIZE { + if length >= MAX_MERKLE_TREE_PROOF_SIZE { return true; } let proof = MerkleProof::try_construct(hashes, path).unwrap(); @@ -379,7 +379,7 @@ mod test { let hashes = create_monero_hashes(input_vec); let hash = Hash::from_slice(hash.bits.as_slice()); let length = hashes.len(); - if length > MAX_MERKLE_TREE_PROOF_SIZE { + if length >= MAX_MERKLE_TREE_PROOF_SIZE { return true; } let proof = MerkleProof::try_construct(hashes, path).unwrap();