11package ezp
22
33import (
4+ "encoding/binary"
45 "math/big"
56 "math/rand"
67 "time"
78
8- "github.com/ethereum/go-ethereum/crypto"
99 "github.com/ethereum/go-ethereum/crypto/sha3"
1010 "github.com/ethereum/go-ethereum/ethutil"
1111 "github.com/ethereum/go-ethereum/logger"
@@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) {
3232 pow .turbo = on
3333}
3434
35- func (pow * EasyPow ) Search (block pow.Block , stop <- chan struct {}) ([] byte , []byte , []byte ) {
35+ func (pow * EasyPow ) Search (block pow.Block , stop <- chan struct {}) (uint64 , []byte , []byte ) {
3636 r := rand .New (rand .NewSource (time .Now ().UnixNano ()))
3737 hash := block .HashNoNonce ()
3838 diff := block .Difficulty ()
@@ -57,15 +57,15 @@ empty:
5757 for {
5858 select {
5959 case <- stop :
60- return nil , nil , nil
60+ return 0 , nil , nil
6161 default :
6262 i ++
6363
6464 elapsed := time .Now ().UnixNano () - start
6565 hashes := ((float64 (1e9 ) / float64 (elapsed )) * float64 (i - starti )) / 1000
6666 pow .HashRate = int64 (hashes )
6767
68- sha := crypto . Sha3 ( big . NewInt ( r .Int63 ()). Bytes ())
68+ sha := uint64 ( r .Int63 ())
6969 if verify (hash , diff , sha ) {
7070 return sha , nil , nil
7171 }
@@ -75,16 +75,20 @@ empty:
7575 time .Sleep (20 * time .Microsecond )
7676 }
7777 }
78+
79+ return 0 , nil , nil
7880}
7981
8082func (pow * EasyPow ) Verify (block pow.Block ) bool {
8183 return Verify (block )
8284}
8385
84- func verify (hash []byte , diff * big.Int , nonce [] byte ) bool {
86+ func verify (hash []byte , diff * big.Int , nonce uint64 ) bool {
8587 sha := sha3 .NewKeccak256 ()
8688
87- d := append (hash , nonce ... )
89+ n := make ([]byte , 8 )
90+ binary .PutUvarint (n , nonce )
91+ d := append (hash , n ... )
8892 sha .Write (d )
8993
9094 verification := new (big.Int ).Div (ethutil .BigPow (2 , 256 ), diff )
0 commit comments