lighthouse/testing/ef_tests
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
..
src Prioritise important parts of block processing (#3696) 2022-11-30 05:22:58 +00:00
tests Added Merkle Proof Generation for Beacon State (#3674) 2022-11-08 01:58:18 +00:00
.gitignore Add a new bls test (#3235) 2022-10-12 23:40:42 +00:00
Cargo.toml Verify execution block hashes during finalized sync (#3794) 2023-01-09 03:11:59 +00:00
check_all_files_accessed.py Add --light-client-server flag and state cache utils (#3714) 2022-11-11 11:03:18 +00:00
Makefile Various CI fixes (#3813) 2022-12-20 01:34:52 +00:00
README.md Update spec tests to v1.1.0-beta.4 (#2548) 2021-09-25 05:58:35 +00:00

Consensus Specification Tests

This crate parses and executes the test vectors at ethereum/consensus-spec-tests.

Functionality is achieved only via the $ cargo test --features ef_tests command.

Running the Tests

Because the test vectors are very large, we do not download or run them by default. To download them, run (in this directory):

$ make

Note: this may download hundreds of MB of compressed archives from the ethereum/consensus-spec-tests, which may expand into several GB of files.

If successful, you should now have the extracted tests in ./consensus-spec-tests.

Run them with:

$ cargo test --features ef_tests

The tests won't run without the ef_tests feature enabled (this is to ensure that a top-level cargo test --all won't fail on missing files).

Saving Space

When you download the tests, the downloaded archives will be kept in addition to the extracted files. You have several options for saving space:

  1. Delete the archives (make clean-archives), and keep the extracted files. Suitable for everyday use, just don't re-run make or it will redownload the archives.
  2. Delete the extracted files (make clean-test-files), and keep the archives. Suitable for CI, or temporarily saving space. If you re-run make it will extract the archives rather than redownloading them.
  3. Delete everything (make clean). Good for updating to a new version, or if you no longer wish to run the EF tests.