@@ -97,6 +97,9 @@ impl Mmr {
97
97
/// - The specified leaf position is out of bounds for this MMR.
98
98
/// - The specified `forest` value is not valid for this MMR.
99
99
pub fn open_at ( & self , pos : usize , forest : Forest ) -> Result < MmrProof , MmrError > {
100
+ if forest > self . forest {
101
+ return Err ( MmrError :: ForestOutOfBounds ( forest. num_leaves ( ) , self . forest . num_leaves ( ) ) ) ;
102
+ }
100
103
let ( _, path) = self . collect_merkle_path_and_value ( pos, forest) ?;
101
104
102
105
Ok ( MmrProof {
@@ -150,10 +153,7 @@ impl Mmr {
150
153
/// Returns an error if the specified `forest` value is not valid for this MMR.
151
154
pub fn peaks_at ( & self , forest : Forest ) -> Result < MmrPeaks , MmrError > {
152
155
if forest > self . forest {
153
- return Err ( MmrError :: InvalidPeaks ( format ! (
154
- "requested forest {forest} exceeds current forest {}" ,
155
- self . forest
156
- ) ) ) ;
156
+ return Err ( MmrError :: ForestOutOfBounds ( forest. num_leaves ( ) , self . forest . num_leaves ( ) ) ) ;
157
157
}
158
158
159
159
let peaks: Vec < Word > = TreeSizeIterator :: new ( forest)
@@ -177,11 +177,17 @@ impl Mmr {
177
177
/// The result is a packed sequence of the authentication elements required to update the trees
178
178
/// that have been merged together, followed by the new peaks of the [Mmr].
179
179
pub fn get_delta ( & self , from_forest : Forest , to_forest : Forest ) -> Result < MmrDelta , MmrError > {
180
- if to_forest > self . forest || from_forest > to_forest {
181
- return Err ( MmrError :: InvalidPeaks ( format ! (
182
- "to_forest {to_forest} exceeds the current forest {} or from_forest {from_forest} exceeds to_forest" ,
183
- self . forest
184
- ) ) ) ;
180
+ if to_forest > self . forest {
181
+ return Err ( MmrError :: ForestOutOfBounds (
182
+ to_forest. num_leaves ( ) ,
183
+ self . forest . num_leaves ( ) ,
184
+ ) ) ;
185
+ }
186
+ if from_forest > to_forest {
187
+ return Err ( MmrError :: ForestOutOfBounds (
188
+ from_forest. num_leaves ( ) ,
189
+ to_forest. num_leaves ( ) ,
190
+ ) ) ;
185
191
}
186
192
187
193
if from_forest == to_forest {
0 commit comments