MCPcopy Create free account
hub / github.com/SmartPool/smartpool-client / Verify

Method Verify

ethereum/ethash/ethash.go:205–244  ·  view source on GitHub ↗

Verify checks whether the block's nonce is valid.

(block pow.Block)

Source from the content-addressed store, hash-verified

203
204// Verify checks whether the block's nonce is valid.
205func (l *Light) Verify(block pow.Block) bool {
206 // TODO: do ethash_quick_verify before getCache in order
207 // to prevent DOS attacks.
208 blockNum := block.NumberU64()
209 if blockNum >= epochLength*2048 {
210 log.Debug(fmt.Sprintf("block number %d too high, limit is %d", epochLength*2048))
211 return false
212 }
213
214 difficulty := block.Difficulty()
215 /* Cannot happen if block header diff is validated prior to PoW, but can
216 happen if PoW is checked first due to parallel PoW checking.
217 We could check the minimum valid difficulty but for SoC we avoid (duplicating)
218 Ethereum protocol consensus rules here which are not in scope of Ethash
219 */
220 if difficulty.Cmp(common.Big0) == 0 {
221 log.Debug("invalid block difficulty")
222 return false
223 }
224
225 cache := l.getCache(blockNum)
226 dagSize := C.ethash_get_datasize(C.uint64_t(blockNum))
227 if l.test {
228 dagSize = dagSizeForTesting
229 }
230 // Recompute the hash using the cache.
231 ok, mixDigest, result := cache.compute(uint64(dagSize), block.HashNoNonce(), block.Nonce())
232 if !ok {
233 return false
234 }
235
236 // avoid mixdigest malleability as it's not included in a block's "hashNononce"
237 if block.MixDigest() != mixDigest {
238 return false
239 }
240
241 // The actual check.
242 target := new(big.Int).Div(maxUint256, difficulty)
243 return result.Big().Cmp(target) <= 0
244}
245
246func h256ToHash(in C.ethash_h256_t) common.Hash {
247 return *(*common.Hash)(unsafe.Pointer(&in.b))

Callers 5

TestEthashVerifyValidFunction · 0.80
TestEthashVerifyInvalidFunction · 0.80

Calls 8

getCacheMethod · 0.95
computeMethod · 0.80
DifficultyMethod · 0.65
NumberU64Method · 0.45
HashNoNonceMethod · 0.45
NonceMethod · 0.45
MixDigestMethod · 0.45
BigMethod · 0.45

Tested by 5

TestEthashVerifyValidFunction · 0.64
TestEthashVerifyInvalidFunction · 0.64