Skip to content

Commit

Permalink
fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Nov 29, 2023
1 parent 629b2e7 commit 851d165
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl BorshDeserialize for MerkleProof {
fn deserialize_reader<R>(reader: &mut R) -> Result<Self, io::Error>
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(),
Expand All @@ -167,7 +167,7 @@ impl BorshDeserialize for MerkleProof {

impl MerkleProof {
fn try_construct(branch: Vec<Hash>, path_bitmap: u32) -> Option<Self> {
if branch.len() > MAX_MERKLE_TREE_PROOF_SIZE {
if branch.len() >= MAX_MERKLE_TREE_PROOF_SIZE {
return None;
}
Some(Self { branch, path_bitmap })
Expand Down Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 851d165

Please sign in to comment.