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

Added the ability to create and verify merkle proofs #61

Merged
merged 2 commits into from
Aug 8, 2018

Conversation

gertjaap
Copy link
Contributor

@gertjaap gertjaap commented Aug 7, 2018

In order to support the pay-to-merkletree effort, i needed the merkletree class to support building and verifying merkle proofs.

I added this to the merkletree class, introduced two new classes:

  • MerkleProof holds the proof data, and can serialize/deserialize them to and from Json

  • MerkleRootNode can be initialized with a precomputed hash in case of reading a merkletree back from a proof - the nodes where the hash was calculated from are not availble, so the root value is just set from the constructor. LeftVal() and RightVal() will return empty.

@metalicjames
Copy link
Member

retest this please

Copy link
Member

@metalicjames metalicjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I'll merge it once these few minor things are cleared up.

@@ -1,14 +1,21 @@
#include <queue>

#include <iostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think iostream is needed here.

class MerkleProof {
public:
MerkleProof();
MerkleProof(Json::Value& json);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json param should be marked const

MerkleProof(Json::Value& json);
int positionInTotalSet;
std::vector<BigNum> leaves;
Json::Value toJson();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toJson should be marked const.


std::shared_ptr<MerkleNode> getLeftNode();
std::shared_ptr<MerkleNode> getRightNode();
MerkleNode* getAncestor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAncestor should be marked const

BigNum root;


CryptoKernel::MerkleNode* findDescendant(BigNum needle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needle should be both const and passed by reference. I think the function itself can be marked const too.

@@ -1,4 +1,5 @@
#include "MerkletreeTests.h"
#include <iostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iostream probably not needed here

@gertjaap
Copy link
Contributor Author

gertjaap commented Aug 8, 2018

Cleaned up the code based on your suggestions (thanks!). Let me know if it requires any additional changes.

@gertjaap gertjaap mentioned this pull request Aug 8, 2018
@metalicjames metalicjames merged commit 2510826 into mit-dci:master Aug 8, 2018
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

Successfully merging this pull request may close these issues.

2 participants