gballet / multiproof-rs

A rust implementation of Alexey Akhunov's multiproof algorithm
Apache License 2.0
32 stars 8 forks source link

Proof of missing key fails if missing key has the same prefix as existing key #61

Closed gballet closed 4 years ago

gballet commented 4 years ago

For example, if the trie has the following keys:

then the structure will be like:

root(branch(leaf([0,0]), leaf([0, 0]), empty, empty, ...)

If then make_multiproof is called with values...

...it will fail because of the following check:

            // This is the simplest case: the key that is found at this 
            // level in the recursion needs to match the unique one in 
            // the list of keys that belong to the proof. 
            if keys.len() != 1 { 
                return Err(format!( 
                    "Expecting exactly 1 key in leaf, got {}: {:?}", 
                    keys.len(), 
                    keys 
                )); 
            }

Instead, it should encode the fact that at most one value is present.