Skip to content

Commit

Permalink
add audit proof
Browse files Browse the repository at this point in the history
  • Loading branch information
laser committed Apr 7, 2018
1 parent f8e7043 commit 64d960c
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 274 deletions.
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
# go-merkle-tree
A Merkle tree, implemented in Golang

> A Merkle Tree, implemented in Golang
Many people have written many things about Merkle Trees. For a good overview (uses, characteristics, etc.), read Marc
Clifton's [_Understanding Merkle Trees - Why use them, who uses them, and how to use them_][1].

## Warning

*Warning: This is alpha software.*

## Usage

### Construction

```go
data := [][]byte{[]byte("alpha"), []byte("beta"), []byte("kappa")}

tree := CreateTree(Sha256DoubleHash, data)

fmt.Println(tree.AsString(hex.EncodeToString, 0))

/*
output:
(B root: 1add1cfdf5df28414b715199a740f80b7f559bd558a3f0c0186e60149ee86620
(B root: 65492c0681df09eb403160136bb648de17f67bd8efc441467c0fc23b8d2950e9
(L root: aa86be763e41db7eaae266afc79ab46d02343c5d3b05da171d351afbd25c1525)
(L root: 05e3bc756e005c1bc5e4daf8a3da95d435af52476b0a0e6d52e719a2b1e3434a))
(B root: 3ae3330dcf932104d42b75b4da386896a628926f411737b34430fa65e526824d
(L root: 4cc9e99389b5f729cbef6fe79e97a6f562841a2852e25e508e3bd06ce0de9c26)
(L root: 4cc9e99389b5f729cbef6fe79e97a6f562841a2852e25e508e3bd06ce0de9c26)))
*/
```

### Audit Proof

```go

blocks := [][]byte{
[]byte("alpha"),
[]byte("beta"),
[]byte("kappa"),
[]byte("gamma"),
[]byte("epsilon"),
[]byte("omega"),
[]byte("mu"),
[]byte("zeta"),
}

tree := NewTree(IdentityHashForTest, blocks)
checksum := treeA.checksumFunc([]byte("omega"))

// for printing checksums
f := func(xs []byte) string {
return string(xs)
}

fmt.Println(tree.GetProofString(tree.root.GetChecksum(), checksum, f))

/*
output:
epsilon + omega = epsilonomega
epsilonomega + muzeta = epsilonomegamuzeta
alphabetakappagamma + epsilonomegamuzeta = alphabetakappagammaepsilonomegamuzeta
*/
```

[1]: https://www.codeproject.com/Articles/1176140/Understanding-Merkle-Trees-Why-use-them-who-uses-t
14 changes: 14 additions & 0 deletions hashing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package merkletree

import "crypto/sha256"

func Sha256DoubleHash(data []byte) []byte {
first := sha256.Sum256(data)
secnd := sha256.Sum256(first[:])

return secnd[:]
}

func IdentityHashForTest(strbytes []byte) []byte {
return strbytes
}
136 changes: 0 additions & 136 deletions main.go

This file was deleted.

137 changes: 0 additions & 137 deletions main_test.go

This file was deleted.

Loading

0 comments on commit 64d960c

Please sign in to comment.