Created
April 10, 2017 00:39
-
-
Save Warchant/774ad06f7c3e0e17bad0359f4bae3411 to your computer and use it in GitHub Desktop.
merkle tree test case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sha3 | |
| import hashlib | |
| def h(s): | |
| return hashlib.sha3_256(s).digest() | |
| # a tree with 4 leafs | |
| d = [0] * (4*2-1) | |
| # store 8 roots for 8 pushes | |
| r = [0] * 8 | |
| # first push | |
| d[3] = h(b'1') | |
| r[0] = d[3] | |
| # second push | |
| d[4] = h(b'1') | |
| d[1] = h(d[3] + d[4]) | |
| r[1] = d[1] | |
| # third push | |
| d[5] = h(b'1') | |
| d[2] = d[5] | |
| d[0] = h(d[1] + d[2]) | |
| r[2] = d[0] | |
| # fourth push | |
| d[6] = h(b'1') | |
| d[2] = h(d[5] + d[6]) | |
| d[0] = h(d[1] + d[2]) | |
| r[3] = d[0] | |
| # fifth push | |
| d[3] = d[0] | |
| d[4] = h(b'1') | |
| d[1] = h(d[3] + d[4]) | |
| r[4] = d[1] | |
| # sixth push | |
| d[5] = h(b'1') | |
| d[2] = d[5] | |
| d[0] = h(d[1] + d[2]) | |
| r[5] = d[0] | |
| # seventh push | |
| d[6] = h(b'1') | |
| d[2] = h(d[5] + d[6]) | |
| d[0] = h(d[1] + d[2]) | |
| r[6] = d[0] | |
| # the last push | |
| d[3] = d[0] | |
| d[4] = h(b'1') | |
| d[1] = h(d[3] + d[4]) | |
| r[7] = d[1] | |
| for i in r: | |
| print i.encode('hex') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment