Context
`Store.from_anchor` validates that the anchor block's `state_root` matches `hash_tree_root(anchor_state)`. If they don't match, the store initialization must fail with an assertion error.
This is a critical safety check: a mismatched state root means the block and state are inconsistent, which would corrupt the fork choice from the start. Every client must enforce this.
What to test
Write a fork choice filler that:
- Creates a valid genesis state and block
- Modifies the block's state_root to a different (incorrect) value
- Attempts to initialize the store with `from_anchor`
- Verifies the initialization fails
Key assertions
- The step is `valid=False`
- The error relates to state root mismatch
- No store is created (initialization aborts cleanly)
Where to add the test
Add to: `tests/consensus/devnet/fc/test_checkpoint_sync.py`
Code skeleton
def test_store_from_anchor_rejects_mismatched_state_root(
fork_choice_test: ForkChoiceTestFiller,
) -> None:
"""Store initialization fails when anchor block state_root doesn't match state."""
# TODO: Check if the fork_choice_test framework supports anchor_block
# overrides (e.g., modifying state_root). If not, this may need
# framework support.
#
# The test should provide an anchor block where:
# block.state_root != hash_tree_root(state)
# and verify Store.from_anchor raises AssertionError.
pass
Note: This test likely requires the framework to support custom anchor blocks with overridden fields. Check `ForkChoiceTest` for anchor customization options.
How to run
uv run fill --fork=devnet --clean -n auto -k test_store_from_anchor_rejects
References
- `Store.from_anchor`: `src/lean_spec/subspecs/forkchoice/store.py` — the assertion check
- `hash_tree_root`: `src/lean_spec/subspecs/ssz/hash.py`
Context
`Store.from_anchor` validates that the anchor block's `state_root` matches `hash_tree_root(anchor_state)`. If they don't match, the store initialization must fail with an assertion error.
This is a critical safety check: a mismatched state root means the block and state are inconsistent, which would corrupt the fork choice from the start. Every client must enforce this.
What to test
Write a fork choice filler that:
Key assertions
Where to add the test
Add to: `tests/consensus/devnet/fc/test_checkpoint_sync.py`
Code skeleton
How to run
References