diff options
Diffstat (limited to 'whisper/whisperv5/envelope.go')
-rw-r--r-- | whisper/whisperv5/envelope.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/whisper/whisperv5/envelope.go b/whisper/whisperv5/envelope.go index 8812ae207..5d882d5dc 100644 --- a/whisper/whisperv5/envelope.go +++ b/whisper/whisperv5/envelope.go @@ -23,10 +23,12 @@ import ( "encoding/binary" "errors" "fmt" - "math" + gmath "math" + "math/big" "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/rlp" @@ -103,8 +105,8 @@ func (e *Envelope) Seal(options *MessageParams) error { for nonce := uint64(0); time.Now().UnixNano() < finish; { for i := 0; i < 1024; i++ { binary.BigEndian.PutUint64(buf[56:], nonce) - h = crypto.Keccak256(buf) - firstBit := common.FirstBitSet(common.BigD(h)) + d := new(big.Int).SetBytes(crypto.Keccak256(buf)) + firstBit := math.FirstBitSet(d) if firstBit > bestBit { e.EnvNonce, bestBit = nonce, firstBit if target > 0 && bestBit >= target { @@ -138,9 +140,9 @@ func (e *Envelope) calculatePoW(diff uint32) { h := crypto.Keccak256(e.rlpWithoutNonce()) copy(buf[:32], h) binary.BigEndian.PutUint64(buf[56:], e.EnvNonce) - h = crypto.Keccak256(buf) - firstBit := common.FirstBitSet(common.BigD(h)) - x := math.Pow(2, float64(firstBit)) + d := new(big.Int).SetBytes(crypto.Keccak256(buf)) + firstBit := math.FirstBitSet(d) + x := gmath.Pow(2, float64(firstBit)) x /= float64(e.size()) x /= float64(e.TTL + diff) e.pow = x @@ -150,8 +152,8 @@ func (e *Envelope) powToFirstBit(pow float64) int { x := pow x *= float64(e.size()) x *= float64(e.TTL) - bits := math.Log2(x) - bits = math.Ceil(bits) + bits := gmath.Log2(x) + bits = gmath.Ceil(bits) return int(bits) } |