0

Fix 'nonce' and 'mixDigest', only change 'extra' to mine a new block.

  • I have no idea what you want :D Could you specify what your question is and describe your problem? Do you mean the input data field? The nonce field there to be altered. That's its purpose. – Donut Nov 27 '18 at 13:20
1

You can change any data to try to find a mine a valid block. You could change the order of the transactions if you want. The reason miners don't do that is because it would be terribly inefficient. It means the miner would have to recompute the state root, log root, receipt root, and half the other stuff in the header. Instead, they just change the nonce since it's much more efficient then changing the entire block.

| improve this answer | |
0

The easist way is to find source code

Sealer.go perform hashimoto algorithm

func (ethash *Ethash) mine(block *types.Block, id int, seed uint64, abort chan struct{}, found chan *types.Block) {
    // Extract some data from the header
    var (
        header  = block.Header()
        hash    = ethash.SealHash(header).Bytes()
        target  = new(big.Int).Div(two256, header.Difficulty)
        number  = header.Number.Uint64()
        dataset = ethash.dataset(number, false)
    )

get block header and select values for mining

ethHash.sealHash(header) is defined in consensus.go

// SealHash returns the hash of a block prior to it being sealed.
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
    hasher := sha3.NewKeccak256()

    rlp.Encode(hasher, []interface{}{
        header.ParentHash,
        header.UncleHash,
        header.Coinbase,
        header.Root,
        header.TxHash,
        header.ReceiptHash,
        header.Bloom,
        header.Difficulty,
        header.Number,
        header.GasLimit,
        header.GasUsed,
        header.Time,
        header.Extra,
    })
    hasher.Sum(hash[:0])
    return hash
}

header.Extra is also used for hash value

Therefore, if nonce and mixDigest is fixed, we can not change Extra

and here is block header struct

type Header struct {
    ParentHash  common.Hash    `json:"parentHash"       gencodec:"required"`
    UncleHash   common.Hash    `json:"sha3Uncles"       gencodec:"required"`
    Coinbase    common.Address `json:"miner"            gencodec:"required"`
    Root        common.Hash    `json:"stateRoot"        gencodec:"required"`
    TxHash      common.Hash    `json:"transactionsRoot" gencodec:"required"`
    ReceiptHash common.Hash    `json:"receiptsRoot"     gencodec:"required"`
    Bloom       Bloom          `json:"logsBloom"        gencodec:"required"`
    Difficulty  *big.Int       `json:"difficulty"       gencodec:"required"`
    Number      *big.Int       `json:"number"           gencodec:"required"`
    GasLimit    uint64         `json:"gasLimit"         gencodec:"required"`
    GasUsed     uint64         `json:"gasUsed"          gencodec:"required"`
    Time        *big.Int       `json:"timestamp"        gencodec:"required"`
    Extra       []byte         `json:"extraData"        gencodec:"required"`
    MixDigest   common.Hash    `json:"mixHash"`
    Nonce       BlockNonce     `json:"nonce"`
}

Ethahs.SealHash() function get all values from block header except nonce and mixDigest

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.