Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

pallet-mmr: batch proofs are sometimes broken #11753

@acatangiu

Description

@acatangiu

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

#10635 added support for generating and/or verifying proofs for multiple leaves at a time.

Single leaf proof generation/verification seems to always work, but multi-leaf (batch) proof generation/verification sometimes fails.

Steps to reproduce

Apply following patch to substrate:

diff --git a/frame/merkle-mountain-range/src/tests.rs b/frame/merkle-mountain-range/src/tests.rs
index d025910a9e..583d97a308 100644
--- a/frame/merkle-mountain-range/src/tests.rs
+++ b/frame/merkle-mountain-range/src/tests.rs
@@ -341,7 +341,8 @@ fn should_verify_batch_proof() {
        // Start off with chain initialisation and storing indexing data off-chain
        // (MMR Leafs)
        let mut ext = new_test_ext();
-       ext.execute_with(|| init_chain(7));     // <---- this works
+       // ext.execute_with(|| init_chain(12)); // <---- this works
+       ext.execute_with(|| init_chain(13));    // <---- this fails
        ext.persist_offchain_overlay();
 
        // Try to generate proof now. This requires the offchain extensions to be present
@@ -349,7 +350,7 @@ fn should_verify_batch_proof() {
        register_offchain_ext(&mut ext);
        let (leaves, proof) = ext.execute_with(|| {
                // when
-               crate::Pallet::<Test>::generate_batch_proof(vec![0, 4, 5]).unwrap()
+               crate::Pallet::<Test>::generate_batch_proof(vec![7, 11]).unwrap()
        });
 
        ext.execute_with(|| {

then run the test and it will incorrectly fail:

<workdir>/substrate$ cargo test -p pallet-mmr should_verify_batch_proof
    Finished test [unoptimized + debuginfo] target(s) in 0.35s
     Running unittests src/lib.rs (target/debug/deps/pallet_mmr-0ea839eef5152467)

running 2 tests
test tests::should_verify_batch_proof_statelessly ... ok
test tests::should_verify_batch_proof ... FAILED

failures:

---- tests::should_verify_batch_proof stdout ----
thread 'tests::should_verify_batch_proof' panicked at 'assertion failed: `(left == right)`
  left: `Err(Error::Verify)`,
 right: `Ok(())`', frame/merkle-mountain-range/src/tests.rs:358:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

As an interesting observation, generating+verifying [7, 11] on a 12-leaves MMR works, while for a 13-leaves MMR it fails.

Metadata

Metadata

Assignees

Labels

I3-bugThe node fails to follow expected behavior.Z2-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions