From 8653db6df0018d08212493e3a3df4677162bdd8f Mon Sep 17 00:00:00 2001 From: Matthew Wampler-Doty Date: Fri, 27 Feb 2015 15:59:33 -0500 Subject: Introducign MixDigest and SeedHash --- pow/block.go | 2 +- pow/ezp/pow.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'pow') diff --git a/pow/block.go b/pow/block.go index 31e194d8d..86a6aa1b0 100644 --- a/pow/block.go +++ b/pow/block.go @@ -5,6 +5,6 @@ import "math/big" type Block interface { Difficulty() *big.Int HashNoNonce() []byte - N() []byte + Nonce() []byte Number() *big.Int } diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index 540381243..8808d7ce0 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -96,5 +96,5 @@ func verify(hash []byte, diff *big.Int, nonce []byte) bool { } func Verify(block pow.Block) bool { - return verify(block.HashNoNonce(), block.Difficulty(), block.N()) + return verify(block.HashNoNonce(), block.Difficulty(), block.Nonce()) } -- cgit v1.2.3 From ba1f4bbe9132103af67c0c46f81c913d6a595d77 Mon Sep 17 00:00:00 2001 From: Matthew Wampler-Doty Date: Fri, 27 Feb 2015 20:56:24 -0500 Subject: Exposing stuff for ethash --- pow/block.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pow') diff --git a/pow/block.go b/pow/block.go index 86a6aa1b0..129f96fd3 100644 --- a/pow/block.go +++ b/pow/block.go @@ -7,4 +7,6 @@ type Block interface { HashNoNonce() []byte Nonce() []byte Number() *big.Int + MixDigest() []byte + SeedHash() []byte } -- cgit v1.2.3 From de9f79133faa1ff5dcd16fb4fd13d06b7799ded9 Mon Sep 17 00:00:00 2001 From: Matthew Wampler-Doty Date: Sat, 28 Feb 2015 14:58:37 -0500 Subject: Introducing ethash --- pow/block.go | 12 ++++++++++-- pow/dagger/dagger.go | 4 ++-- pow/dash/crypto.c | 5 ----- pow/dash/crypto.go | 14 -------------- pow/ezp/pow.go | 8 +++----- pow/pow.go | 2 +- 6 files changed, 16 insertions(+), 29 deletions(-) delete mode 100644 pow/dash/crypto.c delete mode 100644 pow/dash/crypto.go (limited to 'pow') diff --git a/pow/block.go b/pow/block.go index 129f96fd3..eb07bc86e 100644 --- a/pow/block.go +++ b/pow/block.go @@ -1,12 +1,20 @@ package pow -import "math/big" +import ( + "github.com/ethereum/go-ethereum/core/types" + "math/big" +) type Block interface { Difficulty() *big.Int HashNoNonce() []byte Nonce() []byte - Number() *big.Int MixDigest() []byte SeedHash() []byte + NumberU64() uint64 +} + +type ChainManager interface { + GetBlockByNumber(uint64) *types.Block + CurrentBlock() *types.Block } diff --git a/pow/dagger/dagger.go b/pow/dagger/dagger.go index 310f8abdd..3da7683d5 100644 --- a/pow/dagger/dagger.go +++ b/pow/dagger/dagger.go @@ -44,7 +44,7 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) { resChan <- 0 } -func (dag *Dagger) Search(hash, diff *big.Int) *big.Int { +func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) { // TODO fix multi threading. Somehow it results in the wrong nonce amountOfRoutines := 1 @@ -69,7 +69,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int { } } - return big.NewInt(res) + return big.NewInt(res).Bytes(), nil, nil } func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool { diff --git a/pow/dash/crypto.c b/pow/dash/crypto.c deleted file mode 100644 index 9c5a62d16..000000000 --- a/pow/dash/crypto.c +++ /dev/null @@ -1,5 +0,0 @@ -extern char *Sha3(char *, int); -char *sha3_cgo(char *data, int l) -{ - return Sha3(data, l); -} diff --git a/pow/dash/crypto.go b/pow/dash/crypto.go deleted file mode 100644 index 0644a54ae..000000000 --- a/pow/dash/crypto.go +++ /dev/null @@ -1,14 +0,0 @@ -package dash - -/* -char *sha3_cgo(char *, int); // Forward declaration -*/ -import "C" -import ( - "github.com/ethereum/go-ethereum/crypto" -) - -//export Sha3 -func Sha3(data []byte, l int) []byte { - return crypto.Sha3(data) -} diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index 8808d7ce0..49854c3d0 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) { pow.turbo = on } -func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte { +func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) ([]byte, []byte, []byte) { r := rand.New(rand.NewSource(time.Now().UnixNano())) hash := block.HashNoNonce() diff := block.Difficulty() @@ -57,7 +57,7 @@ empty: for { select { case <-stop: - return nil + return nil, nil, nil default: i++ @@ -67,7 +67,7 @@ empty: sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) if verify(hash, diff, sha) { - return sha + return sha, nil, nil } } @@ -75,8 +75,6 @@ empty: time.Sleep(20 * time.Microsecond) } } - - return nil } func (pow *EasyPow) Verify(block pow.Block) bool { diff --git a/pow/pow.go b/pow/pow.go index c94ee40ba..11aecbd6b 100644 --- a/pow/pow.go +++ b/pow/pow.go @@ -1,7 +1,7 @@ package pow type PoW interface { - Search(block Block, stop <-chan struct{}) []byte + Search(block Block, stop <-chan struct{}) ([]byte, []byte, []byte) Verify(block Block) bool GetHashrate() int64 Turbo(bool) -- cgit v1.2.3 From 26de12d9bf23bce7de26b3b6629601ec2e58ad5b Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 3 Mar 2015 21:04:31 +0100 Subject: Changed nonce to a uint64 --- pow/block.go | 5 +++-- pow/ezp/pow.go | 16 ++++++++++------ pow/pow.go | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'pow') diff --git a/pow/block.go b/pow/block.go index eb07bc86e..3bc63978b 100644 --- a/pow/block.go +++ b/pow/block.go @@ -1,14 +1,15 @@ package pow import ( - "github.com/ethereum/go-ethereum/core/types" "math/big" + + "github.com/ethereum/go-ethereum/core/types" ) type Block interface { Difficulty() *big.Int HashNoNonce() []byte - Nonce() []byte + Nonce() uint64 MixDigest() []byte SeedHash() []byte NumberU64() uint64 diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index 49854c3d0..3ca502d06 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -1,11 +1,11 @@ package ezp import ( + "encoding/binary" "math/big" "math/rand" "time" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" @@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) { pow.turbo = on } -func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) ([]byte, []byte, []byte) { +func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) { r := rand.New(rand.NewSource(time.Now().UnixNano())) hash := block.HashNoNonce() diff := block.Difficulty() @@ -57,7 +57,7 @@ empty: for { select { case <-stop: - return nil, nil, nil + return 0, nil, nil default: i++ @@ -65,7 +65,7 @@ empty: hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000 pow.HashRate = int64(hashes) - sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) + sha := uint64(r.Int63()) if verify(hash, diff, sha) { return sha, nil, nil } @@ -75,16 +75,20 @@ empty: time.Sleep(20 * time.Microsecond) } } + + return 0, nil, nil } func (pow *EasyPow) Verify(block pow.Block) bool { return Verify(block) } -func verify(hash []byte, diff *big.Int, nonce []byte) bool { +func verify(hash []byte, diff *big.Int, nonce uint64) bool { sha := sha3.NewKeccak256() - d := append(hash, nonce...) + n := make([]byte, 8) + binary.PutUvarint(n, nonce) + d := append(hash, n...) sha.Write(d) verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff) diff --git a/pow/pow.go b/pow/pow.go index 11aecbd6b..3908e5f76 100644 --- a/pow/pow.go +++ b/pow/pow.go @@ -1,7 +1,7 @@ package pow type PoW interface { - Search(block Block, stop <-chan struct{}) ([]byte, []byte, []byte) + Search(block Block, stop <-chan struct{}) (uint64, []byte, []byte) Verify(block Block) bool GetHashrate() int64 Turbo(bool) -- cgit v1.2.3