From 4306ec3e05a57950e7681d88316b4c29b1a53ce6 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Wed, 22 May 2024 13:22:00 +0200 Subject: [PATCH] Handle the empty leaves case. During a clone of an empty Merkle tree, there was an index out of bounds error. --- arbitrator/prover/src/merkle.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arbitrator/prover/src/merkle.rs b/arbitrator/prover/src/merkle.rs index be1eef8b69..005d3dae16 100644 --- a/arbitrator/prover/src/merkle.rs +++ b/arbitrator/prover/src/merkle.rs @@ -223,7 +223,12 @@ fn new_layer(ty: MerkleType, layer: &Vec, empty_hash: &'static Bytes32) impl Clone for Merkle { fn clone(&self) -> Self { - Merkle::new_advanced(self.ty, self.layers.lock().data[0].clone(), self.min_depth) + let leaves = if self.layers.lock().data.is_empty() { + vec![] + } else { + self.layers.lock().data[0].clone() + }; + Merkle::new_advanced(self.ty, leaves, self.min_depth) } }