| 16 | type SampleReader func(uint64, uint64) (common.Hash, error) |
| 17 | |
| 18 | func hashimoto(kvEntriesBits, kvSizeBits, sampleSizeBits, shardIdx, randomChecks uint64, sampleReader SampleReader, hash0 common.Hash) (common.Hash, []uint64, error) { |
| 19 | var sampleIdxs []uint64 |
| 20 | rowBits := kvEntriesBits + kvSizeBits - sampleSizeBits |
| 21 | for i := uint64(0); i < randomChecks; i++ { |
| 22 | parent := big.NewInt(0) |
| 23 | parent.Mod(new(big.Int).SetBytes(hash0.Bytes()), big.NewInt(1<<rowBits)) |
| 24 | sampleIdx := parent.Uint64() + shardIdx<<rowBits |
| 25 | encodedSample, err := sampleReader(shardIdx, sampleIdx) |
| 26 | if err != nil { |
| 27 | return common.Hash{}, nil, err |
| 28 | } |
| 29 | hash0 = crypto.Keccak256Hash(hash0.Bytes(), encodedSample.Bytes()) |
| 30 | sampleIdxs = append(sampleIdxs, sampleIdx) |
| 31 | } |
| 32 | return hash0, sampleIdxs, nil |
| 33 | } |
| 34 | |
| 35 | func initHash(miner common.Address, mixedHash common.Hash, nonce uint64) common.Hash { |
| 36 | return crypto.Keccak256Hash( |