Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::merkle::compute_merkle_root returns same values #6244

Open
jewelofchaos9 opened this issue Oct 8, 2024 · 0 comments · May be fixed by #6278
Open

std::merkle::compute_merkle_root returns same values #6244

jewelofchaos9 opened this issue Oct 8, 2024 · 0 comments · May be fixed by #6278

Comments

@jewelofchaos9
Copy link

Problem

If last N (size of hash_path) bits of index variable are equal, std::merkle::compute_merkle_root returns same values

Bug

use dep::std;

fn main() {
}

#[test]
fn test_main() {
  let hash_path = [0x1e284aa596cd3d6d3fda0d931804640fff8d3ec437d6741edb730320d711c3b0, 0x169af1edea6b1ee05e68ea2ea6a0ae636d84e0adaa652b7aeac2be73e3a69f53];
  let secret = 0x9532535eab446f71dbfea9dbaac6f16;

  let unique_id_str = "0x4fff9ceb8dd9e0b8d65c59760ea94551";
  let unique_id = U128::from_hex(unique_id_str);
  let note_commitment = std::hash::pedersen_hash([secret, unique_id.to_integer()]);

  let computed_root1 = std::merkle::compute_merkle_root(note_commitment, 8, hash_path);
  let computed_root2 = std::merkle::compute_merkle_root(note_commitment, 16, hash_path);
  let computed_root3 = std::merkle::compute_merkle_root(note_commitment, 32, hash_path);

  assert(computed_root1 == computed_root2);
  assert(computed_root2 == computed_root3);
  assert(computed_root1 == computed_root3);
}

Possible fix

Check if index fits in bitarray of size N.

To Reproduce

  1. Create Noir project for program written in bug section.
  2. Run nargo test

Environment

nargo version = 0.33.0
noirc version = 0.33.0+325dac54efb6f99201de9fdeb0a507d45189607d
(git version hash: 325dac54efb6f99201de9fdeb0a507d45189607d, is dirty: false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

1 participant