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

Proof for key that is overwritten twice is incorrect #2

Closed
hu55a1n1 opened this issue Nov 8, 2021 · 1 comment
Closed

Proof for key that is overwritten twice is incorrect #2

hu55a1n1 opened this issue Nov 8, 2021 · 1 comment

Comments

@hu55a1n1
Copy link

hu55a1n1 commented Nov 8, 2021

Hi,
I just noticed that proofs for keys that are overwritten twice are incorrect and fail to verify using verify_membership().
Here's a failing test ->

fn key_overwrite() {
    let mut tree = AvlTree::new();
    tree.insert("K", [1]);
    tree.insert("K", [0]);
    tree.insert("K", [2]);

    assert!(check_integrity(&tree.root));

    let root = tree
        .root_hash()
        .expect("Unable to retrieve root hash")
        .as_bytes()
        .to_vec();
    let proof = tree
        .get_proof("K")
        .expect("Unable to retrieve a proof for 'K'");
    let spec = get_proof_spec();
    assert!(verify_membership(
        &proof,
        &spec,
        &root,
        "K".as_bytes(),
        &[0]
    ));
}
@CharlyCst
Copy link
Owner

The test is indeed failing but that is because the expected value must be passed as the last argument of verify_membership, in this case "K" has the value 2 but you passed 0, the assertion should be:

    assert!(verify_membership(
        &proof,
        &spec,
        &root,
        "K".as_bytes(),
        &[2]
    ));

And this test does pass, so that's not an issue with the proof or AVL implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants