func (pow *Ethash) light(nonce uint64, miningHash []byte) []byte { cMiningHash := (*C.uint8_t)(unsafe.Pointer(&miningHash)) cnonce := C.uint64_t(nonce) var hashR *C.uint8_t hashR = (*C.uint8_t)(C.malloc(32)) C.ethash_light(hashR, pow.cache, pow.params, cMiningHash, cnonce) ghash_light := C.GoBytes(unsafe.Pointer(hashR), 32) return ghash_light }
func (pow *Ethash) verify(hash []byte, diff *big.Int, nonce uint64) bool { chash := (*C.uint8_t)(unsafe.Pointer(&hash)) cnonce := C.uint64_t(nonce) C.ethash_light(pow.hash, pow.cache, pow.params, chash, cnonce) verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff) res := ethutil.U256(new(big.Int).SetUint64(nonce)) ghash := C.GoBytes(unsafe.Pointer(pow.hash), 32) log.Println("ethash light (on nonce)", ghash, nonce) if res.Cmp(verification) <= 0 { return true } return false }