Git Product home page Git Product logo

merkle.rs's People

Contributors

afck avatar briansmith avatar dingxiangfei2009 avatar fredericjacobs avatar kpcyrd avatar psivesely avatar romac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

merkle.rs's Issues

Serde serialization.

We're using merkle's Proofs in messages that need to be serialized, and want to support Serde in addition to protobuf, so I added a very crude serialization-serde feature in my fork: afck@dd41698

Unfortunately Proof can't just be deserialized, so we added a ProofData that doesn't contain the algorithm field, and conversion functions.

Would you be interested in merging something like that into master? Is there a better way to handle proof deserialization?

Global merkle tree

Sorry for the newbie question.
I want to maintain a global merkle tree to be accessed by all functions. I want to add new values to the already existing Merkle tree at irregular intervals.

Please help.

CT Test Vectors

Since we're choosing to have the same domain separation as CT, we can add a suite of test vectors from a CT library to make sure we're compatible and that Merkle can be a dependency for a CT library.

Protobuf 1.6.0 broke the build.

Protobuf made a backwards-incompatible change without incrementing the major version number, breaking the build.

(A short-term solution would be using "~1.4.5" in Cargo.toml.)

Add index field to Proof struct

Since for some use cases (see #36 and https://github.com/poanetwork/hbbft) knowing the index of a leaf inclusion proof is useful, it might be useful to add an index field to the Proof struct, instead of doing a separate expensive computation to find it. It should be very little additional computation to determine the index as well when already traversing a tree to create an inclusion proof.

When receiving a Proof over the wire from a 3rd party, you should not trust the index is correct, even if the Proof validates. Changing validate to check the index matches in addition to its current purpose, however, should be possible with little overhead.

Guard against malformed lemmas.

#36 adds a panic if Lemma::index is called on a malformed Lemma, i.e. one where any of its sublemmas or itself violates the requirement that sibling_hash.is_some() == sub_lemma.is_some(). A malformed lemma currently can't be constructed, but it could certainly be deserialized, and calling validate is expensive because it does a lot of hashing. Should we:

  • Always do full validation anyway, so that you can't even deserialize a lemma whose hashes don't match?

  • Validate only the structure (i.e. the above requirement) on deserialization?

  • Change the struct definition into one of the following?

pub struct Lemma {
    pub node_hash: Vec<u8>,
    pub sub_lemma: Option<(Positioned<Vec<u8>>, Box<Lemma>)>,
}

pub struct Lemma {
    pub node_hash: Vec<u8>,
    pub sub_lemma: Option<Box<SubLemma>>, // where `SubLemma` contains the sibling hash and position
}

pub struct Lemma {
    pub count: usize,
    // The positions can be computed from the lemma's index.
    pub index: usize,
    pub node_hash: Vec<u8>,
    pub sub_lemma: Option<(Vec<u8>, Box<Lemma>)>,
}

No domain separation between leaf and internal node hashes

It appears from

fn hash_bytes(&'static self, bytes: &[u8]) -> Digest {
digest(self, bytes)
}
fn combine_hashes(&'static self, left: &AsRef<[u8]>, right: &AsRef<[u8]>) -> Digest {
let mut ctx = Context::new(self);
ctx.update(left.as_ref());
ctx.update(right.as_ref());
ctx.finish()
}
that leaf hashes are calculated as H(bytes) and internal node hashes are calculated as H(left || right). Consequentially, it's possible for a leaf to have the same hash as an internal node, and therefore for two different trees to have the same root hash. To avoid this, I suggest calculating leaf and internal node hashes as H(0x00 || bytes) and H(0x01 || left || right), respectively, Certificate Transparency-style.

Proof.valdidate doesn't check value

While the repeated hashing of nodes looks very correct, I cannot see anywhere that the client can verify what the actual value that was included in the proof.

The last Lemma will have the node_hash of the LeafNode. However, there is no check in Proof.verify to check that proof.Value has any relationship to the Lemma that was Valid.

I don't see a reason I cannot construct a valid proof for some data in the tree, then change the Value and present it to you as a valid proof of some fake data.

Generate proof by index.

MerkleTree::gen_proof takes a leaf value and returns a proof for it, but if the value occurs more than once, the user can't specify which proof they want. It would be useful to have a method that returns the proof for the n-th leaf, by index. I'd be happy to try and write code for that, if you are okay with it.

We are using it in hbbft and are currently working around the limitation by making the leafs unique (prepending an index byte), which is wasteful. Conversely, we compute the index from the proof here, which might also make sense as a method of Lemma:
https://github.com/poanetwork/hbbft/blob/71fa32c18f977c45e7869d47e50b4eccfd61d898/src/broadcast.rs#L493

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.