#Issue with merkle tree

12 messages · Page 1 of 1 (latest)

potent onyx
#

Here are the test cases:

#[test]
fn generate_compact_multiproof_sanity_check() {
    let sentence = "Here's an eight word sentence, special for you.";
    let indices = vec![0, 1, 6];
    let expected = (
        14965309246218747603,
        CompactMerkleMultiProof {
            leaf_indices: vec![0, 1, 6],
            hashes: vec![
                1513025021886310739,
                7640678380001893133,
                5879108026335697459,
            ],
        },
    );
    assert_eq!(expected, generate_compact_multiproof(sentence, indices));
}

#[test]
fn validate_compact_multiproof_sanity_check() {
    let proof = (
        14965309246218747603u64,
        CompactMerkleMultiProof {
            leaf_indices: vec![0, 1, 6],
            hashes: vec![
                1513025021886310739,
                7640678380001893133,
                5879108026335697459,
            ],
        },
    );
    let words = vec!["Here's", "an", "for"];
    assert_eq!(true, validate_compact_multiproof(&proof.0, words, proof.1));
}
#

And errors:
---- p6_merkle::tests::generate_compact_multiproof_sanity_check stdout ----
thread 'p6_merkle::tests::generate_compact_multiproof_sanity_check' panicked at 'assertion failed: (left == right)
left: (14965309246218747603, CompactMerkleMultiProof { leaf_indices: [0, 1, 6], hashes: [1513025021886310739, 7640678380001893133, 5879108026335697459] }),
right: (14965309246218747603, CompactMerkleMultiProof { leaf_indices: [0, 1, 6], hashes: [5879108026335697459] })', src/p6_merkle.rs:544:9

---- p6_merkle::tests::validate_compact_multiproof_sanity_check stdout ----
thread 'p6_merkle::tests::validate_compact_multiproof_sanity_check' panicked at 'assertion failed: (left == right)
left: true,
right: false', src/p6_merkle.rs:561:9

#

The merkle tree for the sentence "Here's an eight word sentence, special for you." looks like

             1496
   7801                8480

19721 76406 58791 61287
4155 1633 3049 1467 2635 4135 8246 1513

You can use this to manually check why your proof generation or validation is failing.

#

thx for any help on this side...

hybrid basin
#

well one thing I see is that hash_map::DefaultHasher gives you a random hash on each run of the program

#

how did you set the hash values for tests?

potent onyx
#

hash values are based on the same text:

let sentence = "Here's an eight word sentence, special for you.";
so it should always return the same...
thx for your help!

hybrid basin
#

?eval ```rs
pub fn hash<T: std::hash::Hash>(t: &T) -> u64 {
use std::hash::Hasher;
let mut s = std::collections::hash_map::DefaultHasher::new();
t.hash(&mut s);
s.finish()
}
let sentence = "Here's an eight word sentence, special for you.";
hash(&sentence)

dense craterBOT
#
4238161209639966347```
hybrid basin
#

ok DefaultHasher is just the hashing algorithm

#

RandomState is random

dense craterBOT
#

Unknown Message