sigp / milhouse

Persistent binary merkle tree
Apache License 2.0
18 stars 7 forks source link

`List::from_parts` could drop the `depth` parameter #46

Open michaelsproul opened 3 weeks ago

michaelsproul commented 3 weeks ago

Presently List::from_parts doesn't check that the depth passed in is correct. It is a pub(crate) function and is only intended for internal use where the depth has already been checked. Even so, we could make the API more correct by construction by omitting the depth parameter and deriving it from Self::depth, or by checking the depth and returning an error if it is incorrect. I think the first solution is preferable.

I think the parameter was only passed in as an optimisation to avoid computing it twice, but this is likely a very minor saving.

michaelsproul commented 3 weeks ago

A similar consideration applies to the length passed in. It could be incorrect. However checking the length against the tree is expensive, so at most we could check that it is less than the capacity N.