validate tries the nonce.
(difficulty uint64, headerBytes []byte, addr common.Address, nonce uint64, hashFn hashFn)
| 10 | |
| 11 | // validate tries the nonce. |
| 12 | func 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 | |
| 30 | func ValidateMemory(sender common.Address, blockHash []byte, nonce uint64, difficulty uint64) bool { |
| 31 | return validate(difficulty, blockHash, sender, nonce, scryptFunc) |