yosriady / merkle_tree Goto Github PK
View Code? Open in Web Editor NEW:evergreen_tree: Merkle Tree implementation in pure Elixir
Home Page: http://yos.io/2016/05/19/merkle-trees-in-elixir/
:evergreen_tree: Merkle Tree implementation in pure Elixir
Home Page: http://yos.io/2016/05/19/merkle-trees-in-elixir/
Number of children suggest that we could build k-ary tries (k > 2
). However proofs can only work for the binary tries (2 children)
Do you think it makes sense to support k-ary merkle tries. Otherwise we can simplify the code :)
BTW: proof support for k-ary tries should be fun to implement ๐ค
I think it'd be interesting to be able to visualize and render the trees as an image using graphviz.
Noted here as a reminder.
The following steps have been followed, but result in the error, as shown:
defp deps do
[
{:merkle_tree, "~> 1.1.1", only: [:dev, :test, :prod]}
]
end
mix deps.get
iex -S mix
$ MerkleTree.__info__(:functions)
[__struct__: 0, __struct__: 1, build: 2, new: 1, new: 2]
$ f = MerkleTree.new(['a', 'b', 'c', 'd'], &MerkleTree.Crypto.sha256/1)
%MerkleTree{
blocks: ['a', 'b', 'c', 'd'],
hash_function: &MerkleTree.Crypto.sha256/1,
root: %MerkleTree.Node{
children: [
...
],
value: "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd"
}
}
$ f.blocks()
['a', 'b', 'c', 'd']
$ f.hash_function()
&MerkleTree.Crypto.sha256/1
$ f.root()
...
$ f.t()
** (KeyError) key :t not found in: %MerkleTree{blocks: ['a', 'b', 'c', 'd'], hash_function: &MerkleTree.Crypto.sha256/1, root: %MerkleTree.Node{children: [%MerkleTree.Node{children: [%MerkleTree.Node{children: [], value: "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"}, %MerkleTree.Node{children: [], value: "3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d"}], value: "62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da"}, %MerkleTree.Node{children: [%MerkleTree.Node{children: [], value: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6"}, %MerkleTree.Node{children: [], value: "18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4"}], value: "d3a0f1c792ccf7f1708d5422696263e35755a86917ea76ef9242bd4a8cf4891a"}], value: "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd"}}
Interactive Elixir (1.6.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> proof = MerkleTree.new(~w/a b c d/) |>
...(1)> MerkleTree.Proof.prove(1)
** (UndefinedFunctionError) function MerkleTree.Proof.prove/2 is undefined (module MerkleTree.Proof is not available)
MerkleTree.Proof.prove(%MerkleTree{blocks: ["a", "b", "c", "d"], hash_function: &MerkleTree.Crypto.sha256/1, root: %MerkleTree.Node{children: [%MerkleTree.Node{children: [%MerkleTree.Node{children: [], height: 0, value: "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"}, %MerkleTree.Node{children: [], height: 0, value: "3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d"}], height: 1, value: "62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da"}, %MerkleTree.Node{children: [%MerkleTree.Node{children: [], height: 0, value: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6"}, %MerkleTree.Node{children: [], height: 0, value: "18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4"}], height: 1, value: "d3a0f1c792ccf7f1708d5422696263e35755a86917ea76ef9242bd4a8cf4891a"}], height: 2, value: "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd"}}, 1)
$ elixir --version
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Elixir 1.6.0 (compiled with OTP 20)
TODO
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.