aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
Diffstat (limited to 'whisper')
-rw-r--r--whisper/whisperv2/envelope.go5
-rw-r--r--whisper/whisperv5/envelope.go18
2 files changed, 14 insertions, 9 deletions
diff --git a/whisper/whisperv2/envelope.go b/whisper/whisperv2/envelope.go
index 7110ab457..9f1c68204 100644
--- a/whisper/whisperv2/envelope.go
+++ b/whisper/whisperv2/envelope.go
@@ -23,9 +23,11 @@ import (
"crypto/ecdsa"
"encoding/binary"
"fmt"
+ "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"
@@ -66,7 +68,8 @@ func (self *Envelope) Seal(pow time.Duration) {
for i := 0; i < 1024; i++ {
binary.BigEndian.PutUint32(d[60:], nonce)
- firstBit := common.FirstBitSet(common.BigD(crypto.Keccak256(d)))
+ d := new(big.Int).SetBytes(crypto.Keccak256(d))
+ firstBit := math.FirstBitSet(d)
if firstBit > bestBit {
self.Nonce, bestBit = nonce, firstBit
}
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)
}