Skip to content

Commit

Permalink
bug: Remove leaf data from BMT proofs (#502)
Browse files Browse the repository at this point in the history
* Update BMT prove and verify

* Update binary.rs

* Update

* Update test helpers verify

* Clippy

* comment

* Clippy

* Update merkle_tree.rs

* whitespace

* fmt

* Update CHANGELOG.md
  • Loading branch information
Brandon Vrooman authored Jul 10, 2023
1 parent b8d06c9 commit b8407f7
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 312 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Description of the upcoming release here.

### Breaking

- [#502](https://github.com/FuelLabs/fuel-vm/pull/502) The algorithm used by the
binary Merkle tree for generating Merkle proofs has been updated to remove
the leaf data from the proof set. This change allows BMT proofs to conform
to the format expected by the Solidity contracts used for verifying proofs.

## [Version 0.34.1]

Mainly new opcodes prices and small performance improvements in the `BinaryMerkleTree`.
Expand Down
89 changes: 29 additions & 60 deletions fuel-merkle/src/binary/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,9 @@ mod test {
let leaf_0 = leaf_sum(data[0]);

{
let proof = tree.prove(0).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(0).unwrap();
assert_eq!(root, leaf_0);
assert_eq!(set[0], leaf_0);
assert!(proof_set.is_empty());
}
}

Expand Down Expand Up @@ -220,80 +217,52 @@ mod test {
let node_7 = node_sum(&node_3, &node_11);

{
let proof = tree.prove(0).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(0).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_0);
assert_eq!(set[1], leaf_1);
assert_eq!(set[2], node_5);
assert_eq!(set[3], node_11);
assert_eq!(proof_set[0], leaf_1);
assert_eq!(proof_set[1], node_5);
assert_eq!(proof_set[2], node_11);
}
{
let proof = tree.prove(1).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(1).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_1);
assert_eq!(set[1], leaf_0);
assert_eq!(set[2], node_5);
assert_eq!(set[3], node_11);
assert_eq!(proof_set[0], leaf_0);
assert_eq!(proof_set[1], node_5);
assert_eq!(proof_set[2], node_11);
}
{
let proof = tree.prove(2).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(2).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_2);
assert_eq!(set[1], leaf_3);
assert_eq!(set[2], node_1);
assert_eq!(set[3], node_11);
assert_eq!(proof_set[0], leaf_3);
assert_eq!(proof_set[1], node_1);
assert_eq!(proof_set[2], node_11);
}
{
let proof = tree.prove(3).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(3).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_3);
assert_eq!(set[1], leaf_2);
assert_eq!(set[2], node_1);
assert_eq!(set[3], node_11);
assert_eq!(proof_set[0], leaf_2);
assert_eq!(proof_set[1], node_1);
assert_eq!(proof_set[2], node_11);
}
{
let proof = tree.prove(4).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(4).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_4);
assert_eq!(set[1], leaf_5);
assert_eq!(set[2], leaf_6);
assert_eq!(set[3], node_3);
assert_eq!(proof_set[0], leaf_5);
assert_eq!(proof_set[1], leaf_6);
assert_eq!(proof_set[2], node_3);
}
{
let proof = tree.prove(5).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(5).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_5);
assert_eq!(set[1], leaf_4);
assert_eq!(set[2], leaf_6);
assert_eq!(set[3], node_3);
assert_eq!(proof_set[0], leaf_4);
assert_eq!(proof_set[1], leaf_6);
assert_eq!(proof_set[2], node_3);
}
{
let proof = tree.prove(6).unwrap();
let root = proof.0;
let set = proof.1;

let (root, proof_set) = tree.prove(6).unwrap();
assert_eq!(root, node_7);
assert_eq!(set[0], leaf_6);
assert_eq!(set[1], node_9);
assert_eq!(set[2], node_3);
assert_eq!(proof_set[0], node_9);
assert_eq!(proof_set[1], node_3);
}
}
}
Loading

0 comments on commit b8407f7

Please sign in to comment.