Skip to content

test(fc): store from anchor rejects mismatched state root #570

@tcoratger

Description

@tcoratger

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:

  1. Creates a valid genesis state and block
  2. Modifies the block's state_root to a different (incorrect) value
  3. Attempts to initialize the store with `from_anchor`
  4. 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`

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomerstestsScope: Changes to the spec tests

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions