ethash

package module
v0.0.0-...-5753b13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2021 License: LGPL-3.0 Imports: 18 Imported by: 0

README

ethash1.1-go

Build and Test

Ethash1.1 implementation in the Go Programming Language

Run the tests

go test

Usage

// Copyright (c) 2021 mineruniter969

package main

import (
	"encoding/hex"
	"fmt"
	"math/big"

	ethash "github.com/mineruniter969/ethash1.1-go"
)

func main() {
	blockNumber := uint64(12026746)
	difficulty := big.NewInt(1000000)

	sealHash, err := hex.DecodeString("a37444aa425e5dec89d8f9afe6bedd140f3893d4f0b60528aa5c212b0b20feb5")
	if err != nil {
		panic(err)
	}

	mixDigest, err := hex.DecodeString("1effb9fd7339bbd36db2effedbd7869d93a3d3d9b8080f2e8d8e767832db0331")
	if err != nil {
		panic(err)
	}

	nonce := uint64(0x8866cb397932d01b)

	hasher := ethash.NewHasher()

	err = hasher.Verify(blockNumber, sealHash, mixDigest, nonce, difficulty)
	if err != nil {
		fmt.Println("verification failed", err)
	} else {
		fmt.Println("verification passed")
	}
}

Documentation

Index

Constants

View Source
const (
	EpochLength = 30000 // Blocks per epoch

)

Variables

This section is empty.

Functions

func CacheSize

func CacheSize(block uint64) uint64

CacheSize returns the size of the ethash verification cache that belongs to a certain block number.

func CalcCacheSize

func CalcCacheSize(epoch int) uint64

CalcCacheSize calculates the cache size for epoch. The cache size grows linearly, however, we always take the highest prime below the linearly growing threshold in order to reduce the risk of accidental regularities leading to cyclic behavior.

func CalcDatasetSize

func CalcDatasetSize(epoch int) uint64

CalcDatasetSize calculates the dataset size for epoch. The dataset size grows linearly, however, we always take the highest prime below the linearly growing threshold in order to reduce the risk of accidental regularities leading to cyclic behavior.

func CalcSeedHash

func CalcSeedHash(epoch int) []byte

func DatasetSize

func DatasetSize(block uint64) uint64

DatasetSize returns the size of the ethash mining dataset that belongs to a certain block number.

func GenerateCache

func GenerateCache(dest []uint32, epoch uint64, seed []byte)

GenerateCache creates a verification cache of a given size for an input seed. The cache production process involves first sequentially filling up 32 MB of memory, then performing two passes of Sergio Demian Lerner's RandMemoHash algorithm from Strict Memory Hard Hashing Functions (2014). The output is a set of 524288 64-byte values. This method places the result into dest in machine byte order.

func GenerateDataset

func GenerateDataset(dest []uint32, epoch uint64, cache []uint32)

GenerateDataset generates the entire ethash dataset for mining. This method places the result into dest in machine byte order.

func HashimotoFull

func HashimotoFull(dataset []uint32, hash []byte, nonce uint64) ([]byte, []byte)

HashimotoFull aggregates data from the full dataset (using the full in-memory dataset) in order to produce our final value for a particular header hash and nonce.

func HashimotoLight

func HashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]byte, []byte)

HashimotoLight aggregates data from the full dataset (using only a small in-memory cache) in order to produce our final value for a particular header hash and nonce.

func SealHash

func SealHash(header *types.Header) (hash common.Hash)

func SeedHash

func SeedHash(block uint64) []byte

seedHash is the seed to use for generating a verification cache and the mining dataset.

Types

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

func NewHasher

func NewHasher() *Hasher

func (*Hasher) Verify

func (h *Hasher) Verify(number uint64, sealHash []byte, mixDigest []byte, nonce uint64, difficulty *big.Int) error

Verify verifies block seal. This method returns nil if the block is correct, and a non-nil error if the block is incorrect.

func (*Hasher) VerifyWithoutMix

func (h *Hasher) VerifyWithoutMix(number uint64, sealHash []byte, nonce uint64, difficulty *big.Int) error

VerifyWithoutMix accomplishes the same task as Verify does, but without the mix digest verification

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL