Code Monkey home page Code Monkey logo

merklecpp's Introduction

Continuous Integration Documentation

merklecpp

A header-only C++ library for creation and manipulation of Merkle trees. It supports the usual operations, like hash insertion, root computation, and path extraction, as well as some more unusual features like flushing, retracting, and tree segment serialisation.

Usage

#include <merklecpp.h>

merkle::Tree::Hash hash("fa8f44eabb728d4020e7f33d1aa973faaef19de6c06679bccdc5100a3c01f54a");

merkle::Tree tree;
tree.insert(hash);
...
auto root = tree.root();
auto path = tree.path(0);
assert(path->verify(root));

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

merklecpp's People

Contributors

achamayou avatar ashamis avatar heidihoward avatar jumaffre avatar microsoft-github-operations[bot] avatar wintersteiger 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

merklecpp's Issues

How to update the value of a leaf_node, and how to delete a leaf_node of a merkle tree?

I have built a merkle tree by tree.insert(hashes), and then I want to update the value of a leaf_node and update the value of the node in the path, but don't build a new tree, how can i complish this goal? I didn't find the functions in the TreeT that I can use. And if I want to add a new leaf, I can insert it, and it will automatically modify the tree, but how can I delete a node, and it will automatically modify the tree too. Thanks so much for seeing here, english is not my native language, sorry for not flunent.

The size of the serialization path is wrong

Hello! The size returned by the serialised_size() method of the path is inconsistent with the actual serialization size.

int main() {
  merkle::Tree::Hash hash("fa8f44eabb728d4020e7f33d1aa973faaef19de6c06679bccdc5100a3c01f54a");
  merkle::Tree tree;
  tree.insert(hash);
  auto root = tree.root();
  auto path = tree.path(0);

  std::cout << path->serialised_size() << std::endl;
  // output: 32

  std::vector<uint8_t> serialised_path;
  path->serialise(serialised_path);
  std::cout << serialised_path.size() << std::endl;
  // output: 56

  return 0;
}

Basic example not working

Hello,

I noticed that the original example provided in the main documentation page of the repo isn't working.

For example, the path method which is present on the tree structure, doesn't return a reference but a pointer... which makes this line in the example wrong:

auto path = tree.path(0);
assert(path.verify(root));

Which should be:

auto path = tree.path(0);
assert(path->verify(root));

But even if we fix this little issue, another come just after (with the VS compiler in my case), which comes from the line

throw std::runtime_error("invalid hash string");

After some research, the problem comes from the hash size passed in parameters, the hash should be of size 32bits, but the provided example only provide a string "message", which is not 32bits, hence making the example crash.

I think this should be explained in the documentation, because it's not obvious that the string should be 32 bits.

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.