diff --git a/arbitrator/prover/src/merkle.rs b/arbitrator/prover/src/merkle.rs index 98ba6591f0..4a1278b4cb 100644 --- a/arbitrator/prover/src/merkle.rs +++ b/arbitrator/prover/src/merkle.rs @@ -377,7 +377,7 @@ impl Merkle { // This will set one or no values depending on if the length was even or odd. layers.dirty_leaf_parents[(start >> 1)..].fill(true); // This then resizes and marks the dirty leaf parents as dirty. - layers.dirty_leaf_parents.resize(new_len >> 1, true); + layers.dirty_leaf_parents.resize((new_len + 1) >> 1, true); Ok(layers.data[0].len()) } } @@ -528,6 +528,20 @@ mod test { assert_eq!(merkle.capacity(), 1024); } + #[test] + fn resize_and_set_odd() { + let merkle = Merkle::new_advanced(MerkleType::Value, vec![Bytes32::from([1; 32])], 20); + merkle.resize(9).expect("resize failed"); + merkle.set(8, Bytes32::from([2; 32])); + } + + #[test] + fn resize_and_set_even() { + let merkle = Merkle::new_advanced(MerkleType::Value, vec![Bytes32::from([1; 32])], 20); + merkle.resize(10).expect("resize failed"); + merkle.set(9, Bytes32::from([2; 32])); + } + #[test] #[ignore = "This is just used for generating the zero hashes for the memory merkle trees."] fn emit_memory_zerohashes() {