Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
ec0d19c
Implement basic version of SM link generator
mkalinin Dec 12, 2023
597a64f
Remove numpy as a dependency
mkalinin Dec 18, 2023
ed33ad5
Clean up generator's code
mkalinin Dec 18, 2023
ceddbb9
Add debug output
mkalinin Dec 18, 2023
19feb0b
Add anchor_epoch as a parameter and debug checks
mkalinin Dec 18, 2023
3d07a72
Switch sm_links generator to minizinc model
mkalinin Dec 19, 2023
30c6f21
Rename sm_links test and its deps
mkalinin Dec 21, 2023
dd8f29c
Disable debug mode
mkalinin Dec 21, 2023
1985e82
Fixes and polishing
mkalinin Dec 21, 2023
9812d3e
Update sm_links test and generator
mkalinin Dec 28, 2023
b091637
Fix contraint reachability problem
mkalinin Dec 28, 2023
a1c357f
Update debug output
mkalinin Dec 28, 2023
785b739
Add CLI args to fork choice generator
mkalinin Dec 29, 2023
b0ad5b8
Fix bugs, inrease verbosity
mkalinin Feb 13, 2024
5bcb503
Add basic block tree model instantiator
mkalinin Feb 15, 2024
ffa8681
Minor fixes
mkalinin Feb 27, 2024
e9268bc
Add block cover instantiator
mkalinin Mar 14, 2024
0aa63b0
Update block_cover3 model and fix instantiator
mkalinin Mar 29, 2024
9e6d3b5
Sort tips before sampling
ericsson49 Apr 1, 2024
a8af4f1
Added an option to pre-generated model instances: `--fc-gen-instances…
ericsson49 Apr 1, 2024
e760f83
Sample yaml file with pre-generated instances
ericsson49 Apr 1, 2024
e185227
minor fixes
ericsson49 Apr 1, 2024
7d12c61
rename params
ericsson49 Apr 1, 2024
961f169
Modified `filter_block_tree_generator.py`: added an option to loa pre…
ericsson49 Apr 1, 2024
1d995b9
Implement on_attestation
mkalinin Apr 6, 2024
7ac53af
Implement attester slashings
mkalinin Apr 7, 2024
edd0f28
Update block tree model
mkalinin Apr 8, 2024
af31916
Added `test_gen.py` driver to generate all tests from a single confi.
ericsson49 Apr 2, 2024
b5e758e
Implement invalid blocks
mkalinin Apr 8, 2024
56a5d27
Omit valid: true for on_attestation
mkalinin Apr 9, 2024
0398298
Mutation operators/shuffling added.
ericsson49 Apr 9, 2024
c304bf3
Added customizeable test_name.
ericsson49 Apr 10, 2024
925dede
Pass block parents as a parameter, update block tree model
mkalinin Apr 10, 2024
efb9f07
Added command line args for `with_attester_slashings` and `with_inval…
ericsson49 Apr 10, 2024
3b5933f
Refactor block parents parametrization
mkalinin Apr 10, 2024
e5bef5b
Modified solutions construction
ericsson49 Apr 10, 2024
5cf2cfa
Changed block_tree format
ericsson49 Apr 10, 2024
c3c551a
Added test instances generator (from MiniZinc models to yaml)
ericsson49 Apr 10, 2024
c34eba3
Add invalid attestations and slashings
mkalinin Apr 11, 2024
a88ddf3
Handle slashed proposer as it were a regular invalid block
mkalinin Apr 11, 2024
5889498
Fix valid block production
mkalinin Apr 11, 2024
d2fd7fc
fix solutions construction
ericsson49 Apr 11, 2024
5e7a499
fixed file format (`sm_links` instead of `sources/targets`)
ericsson49 Apr 11, 2024
cab2f78
renamed GENERATOR_NAME
ericsson49 Apr 11, 2024
4429b61
fixed solution constuction (`sm_links` instead of `sources/targets`)
ericsson49 Apr 11, 2024
1a0773b
Added a command line option to pass the test_gen configuration path
ericsson49 Apr 16, 2024
ea1a6ab
Ensure voting source matches the attestation source
mkalinin Apr 22, 2024
750cf9e
Remove over constraining assert check
mkalinin Apr 22, 2024
b0ae767
Ensure that epoch 1 is not supposed to be justified
mkalinin Apr 23, 2024
b5acd95
Re-formatted test_gen config
ericsson49 Apr 23, 2024
7a8a3ef
Refactoring of test generator routines: streamline code organization
ericsson49 Apr 23, 2024
34accfe
Improve block cover instantiator to accommodate for more blocks
mkalinin Apr 24, 2024
a90caca
Fix unexpected justifed checkpoint in block cover
mkalinin Apr 25, 2024
55623e5
Make block cover instantiator more flexible
mkalinin Apr 25, 2024
27ff1b2
Make justified epoch 1 check stricter
mkalinin Apr 26, 2024
2b689e2
Fixed bug in `is_leaf``
ericsson49 Apr 25, 2024
929d4ff
temporary small refactoring
ericsson49 May 1, 2024
347a24f
refactoring
ericsson49 May 1, 2024
6665a38
Extend FC checks with filtered block weights
mkalinin May 10, 2024
3c251cd
Move instantiators into a separate dir
mkalinin May 10, 2024
56223da
Unify test case instantiator
mkalinin May 11, 2024
1319734
new instance configurations added: small, smoke, standard
ericsson49 May 15, 2024
a08299d
new testgen configs added: small, smoke and standard
ericsson49 May 15, 2024
3776b3d
add block_cover instances
ericsson49 May 15, 2024
ffef619
add block_tree_tree instances
ericsson49 May 15, 2024
47a0fa1
add block_tree_other instances
ericsson49 May 15, 2024
187ebd8
fix typos
ericsson49 May 15, 2024
b797d66
put test configs into separate directories
ericsson49 May 15, 2024
e8f4655
Fix test DNA file paths to run test_gen from root dir
mkalinin May 29, 2024
b25697d
Use pyspec_tests suite name for fc generated tests
mkalinin May 29, 2024
ed9c9e3
Add bls_setting to meta data for fc generated tests
mkalinin May 29, 2024
862a6b7
Add pseudo randao_reveal for fc generated tests
mkalinin May 29, 2024
a55ace3
Replace filtered_block_weights with viable_for_head_roots_and_weights
mkalinin May 29, 2024
8c8a563
Fix pseudo randao_reveal computation
mkalinin May 29, 2024
05195c1
Make MutationGenerator serializeable
ericsson49 May 30, 2024
e66339d
Make TestProviders finer granular
ericsson49 May 30, 2024
832b213
Fixed typo in standard/block_cover config
ericsson49 May 30, 2024
05d8816
Fixed a problem with running in multiprocessor node - incompatible re…
ericsson49 Jun 11, 2024
65b954f
Added shuffling_test (by splitting block_weight_test)
ericsson49 Jun 11, 2024
37ab647
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
29d998e
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
f08c626
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
e17b10b
Refactoring to improve code structure and ensure deterministic behavi…
ericsson49 Jun 12, 2024
ee347f8
Code restructuring
ericsson49 Jun 12, 2024
c4f4b22
refactored code, to use test data from instantiators, instead of full…
ericsson49 Jun 18, 2024
078b53e
Code reorg: make helper methods
ericsson49 Jun 19, 2024
0adf423
split `yield_fork_choice_test_case` into two steps:
ericsson49 Jun 19, 2024
987632c
refactoring of mutated test generation
ericsson49 Jun 19, 2024
d5087fe
re-worked test generation: skip duplicate tick events
ericsson49 Jun 20, 2024
2552b41
Links added:
ericsson49 Jun 25, 2024
f22f53e
Test runner added
ericsson49 Jun 27, 2024
a00074f
Typos fixed - increase amount of tests for shuffling test
ericsson49 Jun 27, 2024
1695fca
Fixed some bugs with scheduling
ericsson49 Jun 27, 2024
bd9db99
Move mutation_operators to instantiators
ericsson49 Jun 27, 2024
fe436b3
Extend fork choice test format
mkalinin Jun 28, 2024
7ac2c67
remove with_viable_for_head_weights=True (kept by mistake)
ericsson49 Jun 28, 2024
bc6d424
put back MutationOps (dropped by mistake)
ericsson49 Jun 28, 2024
e6645b0
switch to DENEB as the default fork
ericsson49 Jun 28, 2024
4166df6
remove debug prints and recovery property from test steps
ericsson49 Jul 1, 2024
c59bedd
drop unnecessary comments
ericsson49 Jul 1, 2024
6e11fd8
Drop `checks_with_viable_for_head_weights` which is not a part of `on…
ericsson49 Jul 1, 2024
dba71be
added `viable_for_head_roots_and_weights` check description
ericsson49 Jul 1, 2024
2792094
fixed names (small -> tiny, smoke -> small)
ericsson49 Jul 1, 2024
2009fca
added instructions how to generate and run tests
ericsson49 Jul 1, 2024
8591ccf
Update README.md
ericsson49 Jul 1, 2024
a551ecf
Update README.md
ericsson49 Jul 1, 2024
c45fe3c
Update tests/formats/fork_choice/README.md
ericsson49 Jul 2, 2024
5841df7
Fix viable_for_head_roots_and_weights in example
mkalinin Jul 2, 2024
f7cb6fb
Added a line about EF grant
ericsson49 Jul 3, 2024
86d6db2
Changed viable_for_head_roots_and_weights format
ericsson49 Jul 3, 2024
6703d6d
Added CLI switch to turn on multiprocessing mode
ericsson49 Jan 14, 2025
693272b
Fixed `gen_runner` call according to recent changes
ericsson49 May 29, 2025
9e3611c
Got rid of `instance_generator.py`.
ericsson49 May 29, 2025
fbcdf1f
Switch to ELECTRA.
ericsson49 May 29, 2025
dfee7de
Fix --fc-gen-multi-processing behaviour (for compatibility).
ericsson49 May 29, 2025
e1147cb
Remvoed trailing spaces
ericsson49 May 30, 2025
af73676
Removed unused imports
ericsson49 May 30, 2025
b2b621c
Removed import of non-existing `settings` module
ericsson49 May 30, 2025
622383e
Refacoring: use `FCTestKind` class instead of `str`
ericsson49 Jun 10, 2025
b27260b
Refactoring: simplify invocation of instantiators.
ericsson49 Jun 10, 2025
de6398a
Refactoring: simplify test case enumeration
ericsson49 Jun 10, 2025
f308132
Refactoring: simplify `model` directrory structure
ericsson49 Jun 10, 2025
51407bc
Execute `print` under debug mode only.
ericsson49 Jun 10, 2025
7db8e67
Drop regular `test_sm_links_tree_model.py` test **from compliance** t…
ericsson49 Jun 10, 2025
51c7483
Fix spellingZ
ericsson49 Jun 10, 2025
db07ec0
Removed unused var
ericsson49 Jun 10, 2025
73bef45
Removed unused var
ericsson49 Jun 10, 2025
e440759
Fix typo
ericsson49 Jun 10, 2025
a6c3560
Fix formatting
ericsson49 Jun 10, 2025
580037a
Fix formatting
ericsson49 Jun 10, 2025
7a19fc5
Fix formatting
ericsson49 Jun 10, 2025
4c15415
Fix formatting
ericsson49 Jun 10, 2025
4c3696a
Fix formatting
ericsson49 Jun 10, 2025
f66818b
Fix formatting
ericsson49 Jun 10, 2025
66ac462
Rename `fork_choice_generated` to `compliance_runners`
ericsson49 Jun 10, 2025
265af25
Moved to subfolder 'fork_choice`
ericsson49 Jun 10, 2025
514ac7f
Fixed references/links
ericsson49 Jun 10, 2025
7c3ac71
Move `scheduler.py` and `test_provider.py` to `instantiators/`.
ericsson49 Jun 10, 2025
6f8333c
renamed generator name to
ericsson49 Jun 10, 2025
1b2ba04
Remove dead code
ericsson49 Jun 16, 2025
fba66aa
Remove dead code
ericsson49 Jun 16, 2025
e356f85
Remove dead code
ericsson49 Jun 16, 2025
c42173a
Use relative imports
ericsson49 Jun 17, 2025
08488d4
Resolve configuration file names relative to config file path (vs cur…
ericsson49 Jun 17, 2025
ebc36ae
Fix formatting issues
ericsson49 Jun 17, 2025
d842c00
Fixed formatting issues
ericsson49 Jun 17, 2025
35b8d46
Use paths relative to base directory.
ericsson49 Jun 17, 2025
1db7162
Fix formatting issues
ericsson49 Jun 17, 2025
c24e187
Added `minizinc` and `tqdm` dependencies
ericsson49 Jun 17, 2025
bd40172
Updated documentation for the fork choice complaince test generator.
ericsson49 Jun 17, 2025
f06546a
Allow overriding `forks` and `presets` from CLI.
ericsson49 Jun 17, 2025
af3041b
Can specify test suite typei (tiny, small or standard) to generate di…
ericsson49 Jun 17, 2025
3000458
Fix typo
ericsson49 Jun 17, 2025
cc08434
Make less verbose
ericsson49 Jun 17, 2025
9613890
Added command
ericsson49 Jun 17, 2025
af5c02f
Fixed a typo
ericsson49 Jun 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ NORM = $(shell tput sgr0)
# Print target descriptions.
help:
@echo "make $(BOLD)clean$(NORM) -- delete all untracked files"
@echo "make $(BOLD)comptests$(NORM) -- generate compliance tests"
@echo "make $(BOLD)coverage$(NORM) -- run pyspec tests with coverage"
@echo "make $(BOLD)kzg_setups$(NORM) -- generate trusted setups"
@echo "make $(BOLD)lint$(NORM) -- run the linters"
Expand Down Expand Up @@ -242,6 +243,27 @@ kzg_setups: pyspec
--output-dir $(CURDIR)/presets/$$preset/trusted_setups; \
done

COMP_TEST_VECTOR_DIR = $(CURDIR)/../compliance-spec-tests/tests

# Generate compliance tests (fork choice).
# This will forcibly rebuild pyspec just in case.
# To generate compliance tests with a particular configuration, append fc_gen_config=<config>,
# where <config> can be either tiny, small or standard, eg:
# make comptests fc_gen_config=standard
# One can specify threads=N, fork=<fork> or preset=<preset> as with reftests, eg:
# make comptests fc_gen_config=standard fork=deneb preset=mainnet threads=8
comptests: FC_GEN_CONFIG := $(if $(fc_gen_config),$(fc_gen_config),tiny)
comptests: MAYBE_THREADS := $(if $(threads),--threads=$(threads),--fc-gen-multi-processing)
comptests: MAYBE_FORKS := $(if $(fork),--forks $(subst ${COMMA}, ,$(fork)))
comptests: MAYBE_PRESETS := $(if $(preset),--presets $(subst ${COMMA}, ,$(preset)))
comptests: pyspec
@$(PYTHON_VENV) -m tests.generators.compliance_runners.fork_choice.test_gen \
--output $(COMP_TEST_VECTOR_DIR) \
--fc-gen-config $(FC_GEN_CONFIG) \
$(MAYBE_THREADS) \
$(MAYBE_FORKS) \
$(MAYBE_PRESETS)

###############################################################################
# Cleaning
###############################################################################
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ lint = [
]
generator = [
"filelock==3.18.0",
"minizinc==0.10.0",
"pathos==0.3.4",
"pytest==8.4.0",
"python-snappy==0.7.3",
"rich==14.0.0",
"tqdm==4.67.1",
]
docs = [
"mdx-truly-sane-lists==1.3",
Expand Down
58 changes: 38 additions & 20 deletions tests/core/pyspec/eth2spec/test/helpers/fork_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ def run_func():
yield from with_blob_data(spec, blob_data, run_func)


def add_attestation(spec, store, attestation, test_steps, is_from_block=False):
spec.on_attestation(store, attestation, is_from_block=is_from_block)
def add_attestation(spec, store, attestation, test_steps, is_from_block=False, valid=True):
run_on_attestation(spec, store, attestation, is_from_block=is_from_block, valid=valid)
yield get_attestation_file_name(attestation), attestation
test_steps.append({"attestation": get_attestation_file_name(attestation)})
if valid:
test_steps.append({"attestation": get_attestation_file_name(attestation)})
else:
test_steps.append({"attestation": get_attestation_file_name(attestation), "valid": False})


def add_attestations(spec, store, attestations, test_steps, is_from_block=False):
Expand Down Expand Up @@ -348,24 +351,39 @@ def output_head_check(spec, store, test_steps):
)


def output_store_checks(spec, store, test_steps):
test_steps.append(
{
"checks": {
"time": int(store.time),
"head": get_formatted_head_output(spec, store),
"justified_checkpoint": {
"epoch": int(store.justified_checkpoint.epoch),
"root": encode_hex(store.justified_checkpoint.root),
},
"finalized_checkpoint": {
"epoch": int(store.finalized_checkpoint.epoch),
"root": encode_hex(store.finalized_checkpoint.root),
},
"proposer_boost_root": encode_hex(store.proposer_boost_root),
def output_store_checks(spec, store, test_steps, with_viable_for_head_weights=False):
checks = {
"time": int(store.time),
"head": get_formatted_head_output(spec, store),
"justified_checkpoint": {
"epoch": int(store.justified_checkpoint.epoch),
"root": encode_hex(store.justified_checkpoint.root),
},
"finalized_checkpoint": {
"epoch": int(store.finalized_checkpoint.epoch),
"root": encode_hex(store.finalized_checkpoint.root),
},
"proposer_boost_root": encode_hex(store.proposer_boost_root),
}

if with_viable_for_head_weights:
filtered_block_roots = spec.get_filtered_block_tree(store).keys()
leaves_viable_for_head = [
root
for root in filtered_block_roots
if not any(c for c in filtered_block_roots if store.blocks[c].parent_root == root)
]

viable_for_head_roots_and_weights = [
{
"root": encode_hex(viable_for_head_root),
"weight": int(spec.get_weight(store, viable_for_head_root)),
}
}
)
for viable_for_head_root in leaves_viable_for_head
]
checks["viable_for_head_roots_and_weights"] = viable_for_head_roots_and_weights

test_steps.append({"checks": checks})


def apply_next_epoch_with_attestations(
Expand Down
8 changes: 8 additions & 0 deletions tests/formats/fork_choice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ finalized_checkpoint: {
root: string, -- Encoded 32-byte value from store.finalized_checkpoint.root
}
proposer_boost_root: string -- Encoded 32-byte value from store.proposer_boost_root
viable_for_head_roots_and_weights: [{
root: string, -- Encoded 32-byte value of filtered_block_tree leaf blocks
weight: int -- Integer value from get_weight(store, viable_block_root)
}]
```

Additionally, these fields if `get_proposer_head` and `should_override_forkchoice_update` features are implemented:
Expand All @@ -196,6 +200,10 @@ For example:
proposer_boost_root: '0xdaa1d49d57594ced0c35688a6da133abb086d191a2ebdfd736fad95299325aeb'
get_proposer_head: '0xdaa1d49d57594ced0c35688a6da133abb086d191a2ebdfd736fad95299325aeb'
should_override_forkchoice_update: {validator_is_connected: false, result: false}
viable_for_head_roots_and_weights: [
{root: '0x533290b6f44d31c925acd08dfc8448624979d48c40b877d4e6714648866c9ddb', weight: 192000000000},
{root: '0x5cfb9d9099cdf1d8ab68ce96cdae9f0fa6eef16914a01070580dfdc1d2d59ec3', weight: 544000000000}
]
```

*Note*: Each `checks` step may include one or multiple items. Each item has to be checked against the current store.
Expand Down
53 changes: 53 additions & 0 deletions tests/generators/compliance_runners/fork_choice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Fork choice compliance test generator

Fork Choice test generator intended to produce tests to validate conformance to the specs of various Fork Choice implementations.

Implementation of the approach described in the [Fork Choice compliance testing framework](https://hackmd.io/@ericsson49/fork-choice-implementation-vs-spec-testing).

Preliminary research has been also performed in this [repo](https://github.com/txrx-research/fork_choice_test_generation/tree/main).

To simplify adoption of the tests, we follow the test format described in the [fork choice test formats documentation](../../../formats/fork_choice/README.md), with a minor exception (new check added).

This work was supported by a grant from the Ethereum Foundation.

# Pre-requisites

Install pyspec using the top-level Makefile, this will install necessary pre-requiesites.

```
> make pyspec
```

# Generating tests

From the root directory:

```
> python -m tests.generators.compliance_runners.fork_choice.test_gen -o ${test_dir} --fc-gen-config ${config}
```
where `config` can be either: `tiny`, `small` or `standard.

Or specify path to the configuration file directly:

```
> python -m tests.generators.compliance_runners.fork_choice.test_gen -o ${test_dir} --fc-gen-config-path ${config_path}
```

There are three configurations in the repo: [tiny](tiny/), [small](small/) and [standard](standard/).

# Running tests

From the root directory:

```
> python -m tests.generators.compliance_runners.fork_choice.test_run -i ${test_dir}
```

# Generating configurations

Files in [tiny](tiny/), [small](small/) and [standard](standard/) are generated with [generate_test_instances.py](generate_test_instances.py), e.g.
```
> python -m tests.generators.compliance_runners.fork_choice.generate_test_instances
```

But one normally doesn't need to generate them.
Loading