mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 989 forks source link

block roots are always zero #572

Closed antiochp closed 6 years ago

antiochp commented 6 years ago

We default the "roots" to ZERO_HASH in BlockHeader::new() -

And we never update them to anything.

Block { 
    header: BlockHeader { 
        version: 1, 
        height: 19, 
        previous: 3b71fd1e, 
        timestamp: Tm { 
            ...
        }, 
        utxo_root: 00000000, 
        range_proof_root: 00000000, 
        kernel_root: 00000000, 
        nonce: 0, 
        ...
    }
}

Q) Should we be setting these somewhere? Maybe more importantly - should we be verifying them somewhere?

ignopeverell commented 6 years ago

Mmmh they're set by the miner here:

https://github.com/mimblewimble/grin/blob/c805f6702013406d981ea7ab25666825e75468a6/grin/src/miner.rs#L588

And checked by the blockchain validation pipeline:

https://github.com/mimblewimble/grin/blob/c805f6702013406d981ea7ab25666825e75468a6/chain/src/pipe.rs#L286

Or did I misunderstand your question?

antiochp commented 6 years ago

Oh I see it now -

https://github.com/mimblewimble/grin/blob/c805f6702013406d981ea7ab25666825e75468a6/grin/src/miner.rs#L581-L588

We call block.validate() before we set the sumtree roots.

I had some debug logging in the block.validate() and was really surprised to see the roots zeroed out (they just hadn't been set yet).