|
|
@ -100,19 +100,29 @@ type Light struct { |
|
|
|
func (l *Light) Verify(block pow.Block) bool { |
|
|
|
func (l *Light) Verify(block pow.Block) bool { |
|
|
|
// TODO: do ethash_quick_verify before getCache in order
|
|
|
|
// TODO: do ethash_quick_verify before getCache in order
|
|
|
|
// to prevent DOS attacks.
|
|
|
|
// to prevent DOS attacks.
|
|
|
|
var ( |
|
|
|
blockNum := block.NumberU64() |
|
|
|
blockNum = block.NumberU64() |
|
|
|
|
|
|
|
difficulty = block.Difficulty() |
|
|
|
|
|
|
|
cache = l.getCache(blockNum) |
|
|
|
|
|
|
|
dagSize = C.ethash_get_datasize(C.uint64_t(blockNum)) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if l.test { |
|
|
|
|
|
|
|
dagSize = dagSizeForTesting |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if blockNum >= epochLength*2048 { |
|
|
|
if blockNum >= epochLength*2048 { |
|
|
|
glog.V(logger.Debug).Infof("block number %d too high, limit is %d", epochLength*2048) |
|
|
|
glog.V(logger.Debug).Infof("block number %d too high, limit is %d", epochLength*2048) |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
difficulty := block.Difficulty() |
|
|
|
|
|
|
|
/* Cannot happen if block header diff is validated prior to PoW, but can |
|
|
|
|
|
|
|
happen if PoW is checked first due to parallel PoW checking. |
|
|
|
|
|
|
|
We could check the minimum valid difficulty but for SoC we avoid (duplicating) |
|
|
|
|
|
|
|
Ethereum protocol consensus rules here which are not in scope of Ethash |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if difficulty.Cmp(common.Big0) == 0 { |
|
|
|
|
|
|
|
glog.V(logger.Debug).Infof("invalid block difficulty") |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache := l.getCache(blockNum) |
|
|
|
|
|
|
|
dagSize := C.ethash_get_datasize(C.uint64_t(blockNum)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if l.test { |
|
|
|
|
|
|
|
dagSize = dagSizeForTesting |
|
|
|
|
|
|
|
} |
|
|
|
// Recompute the hash using the cache.
|
|
|
|
// Recompute the hash using the cache.
|
|
|
|
hash := hashToH256(block.HashNoNonce()) |
|
|
|
hash := hashToH256(block.HashNoNonce()) |
|
|
|
ret := C.ethash_light_compute_internal(cache.ptr, dagSize, hash, C.uint64_t(block.Nonce())) |
|
|
|
ret := C.ethash_light_compute_internal(cache.ptr, dagSize, hash, C.uint64_t(block.Nonce())) |
|
|
|