MCPcopy Create free account
hub / github.com/CPChain/chain / validate

Function validate

admission/verify.go:12–28  ·  view source on GitHub ↗

validate tries the nonce.

(difficulty uint64, headerBytes []byte, addr common.Address, nonce uint64, hashFn hashFn)

Source from the content-addressed store, hash-verified

10
11// validate tries the nonce.
12func validate(difficulty uint64, headerBytes []byte, addr common.Address, nonce uint64, hashFn hashFn) bool {
13 target := big.NewInt(1)
14 target.Lsh(target, 256-uint(difficulty))
15
16 nonceBytes := make([]byte, 8)
17 binary.LittleEndian.PutUint64(nonceBytes, nonce)
18
19 data := bytes.Join(
20 [][]byte{
21 addr.Bytes(),
22 headerBytes,
23 nonceBytes,
24 }, nil)
25
26 hash, _ := hashFn(data)
27 return new(big.Int).SetBytes(hash[:]).Cmp(target) <= 0
28}
29
30func ValidateMemory(sender common.Address, blockHash []byte, nonce uint64, difficulty uint64) bool {
31 return validate(difficulty, blockHash, sender, nonce, scryptFunc)

Callers 4

ValidateMemoryFunction · 0.85
ValidateCpuFunction · 0.85
proveMethod · 0.85

Calls 4

hashFnFuncType · 0.85
CmpMethod · 0.80
SetBytesMethod · 0.80
BytesMethod · 0.65

Tested by 1