lighthouse/consensus
Michael Sproul 4bd2b777ec Verify execution block hashes during finalized sync (#3794)
## Issue Addressed

Recent discussions with other client devs about optimistic sync have revealed a conceptual issue with the optimisation implemented in #3738. In designing that feature I failed to consider that the execution node checks the `blockHash` of the execution payload before responding with `SYNCING`, and that omitting this check entirely results in a degradation of the full node's validation. A node omitting the `blockHash` checks could be tricked by a supermajority of validators into following an invalid chain, something which is ordinarily impossible.

## Proposed Changes

I've added verification of the `payload.block_hash` in Lighthouse. In case of failure we log a warning and fall back to verifying the payload with the execution client.

I've used our existing dependency on `ethers_core` for RLP support, and a new dependency on Parity's `triehash` crate for the Merkle patricia trie. Although the `triehash` crate is currently unmaintained it seems like our best option at the moment (it is also used by Reth, and requires vastly less boilerplate than Parity's generic `trie-root` library).

Block hash verification is pretty quick, about 500us per block on my machine (mainnet).

The optimistic finalized sync feature can be disabled using `--disable-optimistic-finalized-sync` which forces full verification with the EL.

## Additional Info

This PR also introduces a new dependency on our [`metastruct`](https://github.com/sigp/metastruct) library, which was perfectly suited to the RLP serialization method. There will likely be changes as `metastruct` grows, but I think this is a good way to start dogfooding it.

I took inspiration from some Parity and Reth code while writing this, and have preserved the relevant license headers on the files containing code that was copied and modified.
2023-01-09 03:11:59 +00:00
..
cached_tree_hash Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
fork_choice Enable proposer boost re-orging (#2860) 2022-12-13 09:57:26 +00:00
int_to_bytes Update to Rust 1.59 and 2021 edition (#3038) 2022-02-25 00:10:17 +00:00
merkle_proof Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
proto_array Enable proposer boost re-orging (#2860) 2022-12-13 09:57:26 +00:00
safe_arith Inline safe_arith methods (#3229) 2022-05-31 06:09:12 +00:00
serde_utils Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
ssz Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
ssz_derive Update to Rust 1.59 and 2021 edition (#3038) 2022-02-25 00:10:17 +00:00
ssz_types Prioritise important parts of block processing (#3696) 2022-11-30 05:22:58 +00:00
state_processing Clippy lints for rust 1.66 (#3810) 2022-12-16 04:04:00 +00:00
swap_or_not_shuffle Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
tree_hash Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
tree_hash_derive Use SmallVec for TreeHash packed encoding (#3581) 2022-09-16 08:54:06 +00:00
types Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00