fastmerkle

package module
v0.0.0-...-f92dd94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README ΒΆ

Overview

fastmerkle is fast tooling for generating Merkle trees, as well as generating and verifying Merkle proofs. Currently, the supported hashing strategy is Keccak256. The tree generation handles uneven data sets by duplicating the last element on the tree level.

GitHub GitHub branch checks state GitHub all releases

Quick Start πŸ“

The overall API footprint of the package is relatively small.

Package Install

To install the fastmerkle package, run:

go get github.com/Trapesys/fastmerkle

Generate Merkle Tree

// Arbitrary random data used to construct the tree
var randomData [][]byte
randomData = ...

// Generate the Merkle tree
merkleTree, createErr := GenerateMerkleTree(randomData)
if createErr != nil {
// Error occurred during Merkle tree generation
...
}

// Get the Merkle root hash
var merkleRootHash []byte
merkleRootHash = merkleTree.GetRootHash()

Benchmarks

goos: linux
goarch: amd64
pkg: github.com/Trapesys/fastmerkle
cpu: Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz
BenchmarkGenerateMerkleTree5-16          	   41623	     28551 ns/op
BenchmarkGenerateMerkleTree50-16         	    6805	    180395 ns/op
BenchmarkGenerateMerkleTree500-16        	     944	   1289450 ns/op
BenchmarkGenerateMerkleTree1000-16       	     492	   2432432 ns/op
BenchmarkGenerateMerkleTree10000-16      	      52	  23390035 ns/op
BenchmarkGenerateMerkleTree1000000-16    	       1	2165074507 ns/op
PASS
ok  	github.com/Trapesys/fastmerkle	8.942s
# Averaged over 10 runs
# [Num. elements in input set]: [Merkle Tree generation time in s]

10:         0.000059s
100:        0.000316s
1000:       0.001772s
10000:      0.015542s
100000:     0.131613s
1000000:    1.308881s

Copyright 2022 Trapesys

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type MerkleTree ΒΆ

type MerkleTree struct {
	// contains filtered or unexported fields
}

MerkleTree represents the perfect Merkle binary tree

func GenerateMerkleTree ΒΆ

func GenerateMerkleTree(inputData [][]byte) (*MerkleTree, error)

GenerateMerkleTree generates a Merkle tree based on the input data

func (*MerkleTree) Root ΒΆ

func (m *MerkleTree) Root() *Node

Root returns the root of the Merkle tree

func (*MerkleTree) RootHash ΒΆ

func (m *MerkleTree) RootHash() []byte

RootHash returns the root hash fo the Merkle tree

type Node ΒΆ

type Node struct {
	// contains filtered or unexported fields
}

Node represents a single node in the Merkle

func (*Node) Hash ΒΆ

func (n *Node) Hash() []byte

Hash returns the hash of the node's children

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL