aboutsummaryrefslogtreecommitdiffstats
path: root/pow/ethash.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-06 21:00:20 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-03-09 22:50:14 +0800
commitdf72e20cc521b43092b9e3cc684836d4d673e126 (patch)
treef158ca0f28a404f1798133daeddb8af9b0bbe920 /pow/ethash.go
parent023670f6bafcfed28c01857da215217a5dadfaa1 (diff)
downloaddexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar.gz
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar.bz2
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar.lz
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar.xz
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.tar.zst
dexon-df72e20cc521b43092b9e3cc684836d4d673e126.zip
pow: only support prime calculations on Go 1.8 and above
Diffstat (limited to 'pow/ethash.go')
-rw-r--r--pow/ethash.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/pow/ethash.go b/pow/ethash.go
index 602f9324f..9dfeedb78 100644
--- a/pow/ethash.go
+++ b/pow/ethash.go
@@ -35,6 +35,7 @@ import (
)
var (
+ ErrNonceOutOfRange = errors.New("nonce out of range")
ErrInvalidDifficulty = errors.New("non-positive difficulty")
ErrInvalidMixDigest = errors.New("invalid mix digest")
ErrInvalidPoW = errors.New("pow difficulty invalid")
@@ -174,13 +175,18 @@ func NewSharedEthash() PoW {
// Verify implements PoW, checking whether the given block satisfies the PoW
// difficulty requirements.
func (ethash *Ethash) Verify(block Block) error {
+ // Sanity check that the block number is below the lookup table size (60M blocks)
+ number := block.NumberU64()
+ if number/epochLength >= uint64(len(cacheSizes)) {
+ // Go < 1.7 cannot calculate new cache/dataset sizes (no fast prime check)
+ return ErrNonceOutOfRange
+ }
// Ensure twe have a valid difficulty for the block
difficulty := block.Difficulty()
if difficulty.Sign() <= 0 {
return ErrInvalidDifficulty
}
// Recompute the digest and PoW value and verify against the block
- number := block.NumberU64()
cache := ethash.cache(number)
size := datasetSize(number)