Skip to content

Commit e7f2062

Browse files
committed
Clippy
1 parent dbebebf commit e7f2062

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

firewood/src/merkle/mod.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,44 +265,48 @@ impl<T: TrieReader> Merkle<T> {
265265
proof: &RangeProof<impl KeyType, impl ValueType, impl ProofCollection>,
266266
) -> Result<(), api::Error> {
267267
// check that the keys are in ascending order
268-
proof
269-
.key_values()
270-
.windows(2)
271-
.all(|pair| pair[0].0.as_ref() < pair[1].0.as_ref());
268+
let key_values = proof.key_values();
269+
if !key_values
270+
.iter()
271+
.zip(key_values.iter().skip(1))
272+
.all(|(a, b)| a.0.as_ref() < b.0.as_ref())
273+
{
274+
return Err(api::Error::ProofError(
275+
ProofError::NonMonotonicIncreaseRange,
276+
));
277+
}
272278

273279
// check that the start and end proofs are valid
274-
let left = proof
275-
.key_values()
280+
let left = key_values
276281
.first()
277282
.ok_or(api::Error::ProofError(ProofError::Empty))?;
278283

279284
// Verify that first_key (if provided) is <= the first key in the proof
280-
if let Some(ref requested_first) = first_key {
281-
if requested_first.as_ref() > left.0.as_ref() {
282-
return Err(api::Error::InvalidRange {
283-
start_key: requested_first.as_ref().to_vec().into(),
284-
end_key: left.0.as_ref().to_vec().into(),
285-
});
286-
}
285+
if let Some(ref requested_first) = first_key
286+
&& requested_first.as_ref() > left.0.as_ref()
287+
{
288+
return Err(api::Error::InvalidRange {
289+
start_key: requested_first.as_ref().to_vec().into(),
290+
end_key: left.0.as_ref().to_vec().into(),
291+
});
287292
}
288293

289294
proof
290295
.start_proof()
291296
.verify(&left.0, Some(&left.1), root_hash)?;
292297

293-
let right = proof
294-
.key_values()
298+
let right = key_values
295299
.last()
296300
.ok_or(api::Error::ProofError(ProofError::Empty))?;
297301

298302
// Verify that last_key (if provided) is >= the last key in the proof
299-
if let Some(ref requested_last) = last_key {
300-
if requested_last.as_ref() < right.0.as_ref() {
301-
return Err(api::Error::InvalidRange {
302-
start_key: right.0.as_ref().to_vec().into(),
303-
end_key: requested_last.as_ref().to_vec().into(),
304-
});
305-
}
303+
if let Some(ref requested_last) = last_key
304+
&& requested_last.as_ref() < right.0.as_ref()
305+
{
306+
return Err(api::Error::InvalidRange {
307+
start_key: right.0.as_ref().to_vec().into(),
308+
end_key: requested_last.as_ref().to_vec().into(),
309+
});
306310
}
307311

308312
proof

0 commit comments

Comments
 (0)