Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
132 lines (88 sloc) 3.46 KB

Build Status GoDoc GitHub license Coverage Status Go Report Card

Cuckoo Cycle

Overview

This library is Cockoo Cycle implementation in Go mentiond in this paper.

In short,

"Cuckoo Cycle is the first graph-theoretic proof-of-work, and the most memory bound, yet with instant verification"

to prevent ASICs to get half of hash power easier in network, without heavy work for proover.

This library uses below parameters.

  • cycle = 20 to minimize the size impact to transactions.
  • bits of nodes (log2(#nodes)) = 25, memory usage should be around 128MB.
  • easiness = 50% , with edge trimming.

PoW should be finished in 1 second, so hash based PoW should be added with the PoW. The probability of suceeding to find a solution is around 5% and variant is also around 5%. So the solution should be found in 20 seconds and 3 sigma is 60 seconds.

Requirements

  • git
  • go 1.9+

are required to compile.

Install

$ go get -u github.com/AidosKuneen/cuckoo

Usage

	import "github.com/AidosKuneen/cuckoo"
	hash :=[]byte{"some data, which should be 32 bytes"}
	nonces, found := cuckoo.PoW(hash, func(nonces *[ProofSize]uint32) bool {
		//additional PoW (e.g. hash-based PoW) with nonces
		return true //or return false
	}))
	if !found{
		//retry with another hash
	}

	if !cuckoo.Verify(hash, nonces){
		//failed to verify
	}

Cuckoo Time

Using the following test environment...

* Compiler: go version go1.10 linux/amd64
* Kernel: Linux WS777 4.13.5-1-ARCH #1 SMP PREEMPT Fri Oct 6 09:58:47 CEST 2017 x86_64 GNU/Linux
* CPU:  Celeron(R) CPU G1840 @ 2.80GHz 
* Memory: 8 GB

One loop in Cuckoo takes around 630 mS. (Note that in PoW we need to iterate the loop.)

BenchmarkCuckoo2-2   	       2	 633949626 ns/op	244375408 B/op	   30199 allocs/op
PASS

On a cloud server:

* Compiler: go version go1.8.1 linux/amd64
* Kernel: Linux 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
* CPU:  CAMD Ryzen 7 1700X Eight-Core Processor @ 2.20GHz (16 cores)
* Memory: 64 GB

One loop in Cuckoo takes around 330 mS.

BenchmarkCuckoo2-16    	       5	 332289248 ns/op	293002734 B/op	   47726 allocs/op
PASS

On DIGNO M KYL22(Android Smartphone):

* Compiler: go version go1.10 linux/arm
* OS: 	Android 4.2.2
* CPU:	Qualcomm Snapdragon 800 MSM8974 2.2GHz (quad core)
* Memory: 2 GB

One loop in Cuckoo takes around 2.6 seconds.

BenchmarkCuckoo2 	       1	2580786889 ns/op
PASS

Dependencies and Licenses

This software includes a rewrite (from C++ to go) of https://github.com/tromp/cuckoo/, which is covered by the FAIR MINING license.

github.com/AidosKuneen/cuckoo  MIT License
github.com/AidosKuneen/numcpu  MIT License
Golang Standard Library        BSD 3-clause License
You can’t perform that action at this time.