From 86f8c2e642310ecab8cf6e39756e2e5d2ca95496 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 1 Dec 2025 12:23:39 +1100 Subject: [PATCH 1/9] EIP-7916: ProgressiveList and tests --- Cargo.lock | 3 +-- Cargo.toml | 3 +++ consensus/types/src/lib.rs | 2 +- testing/ef_tests/Makefile | 2 +- testing/ef_tests/check_all_files_accessed.py | 1 - testing/ef_tests/src/cases/ssz_generic.rs | 13 ++++++++++++- testing/ef_tests/src/handler.rs | 2 ++ testing/ef_tests/tests/tests.rs | 5 +++++ 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3730f132b3..e78cd10205e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5859,8 +5859,7 @@ dependencies = [ [[package]] name = "milhouse" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "259dd9da2ae5e0278b95da0b7ecef9c18c309d0a2d9e6db57ed33b9e8910c5e7" +source = "git+https://github.com/sigp/milhouse?branch=progressive-list#52bae1f50da93519cfb4ec31f7dab19659be4d14" dependencies = [ "alloy-primitives", "arbitrary", diff --git a/Cargo.toml b/Cargo.toml index 6ccf429b6c6..4fb72987bfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -285,3 +285,6 @@ debug = true [patch.crates-io] quick-protobuf = { git = "https://github.com/sigp/quick-protobuf.git", rev = "681f413312404ab6e51f0b46f39b0075c6f4ebfd" } +# FIXME(sproul): REMOVE patch +# milhouse = { path = "../milhouse" } +milhouse = { git = "https://github.com/sigp/milhouse", branch = "progressive-list" } diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 8e83fed1d9a..35ef299ff71 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -293,6 +293,6 @@ pub use bls::{ }; pub use context_deserialize::{ContextDeserialize, context_deserialize}; pub use kzg::{KzgCommitment, KzgProof, VERSIONED_HASH_VERSION_KZG}; -pub use milhouse::{self, List, Vector}; +pub use milhouse::{self, List, ProgressiveList, Vector}; pub use ssz_types::{BitList, BitVector, FixedVector, VariableList, typenum, typenum::Unsigned}; pub use superstruct::superstruct; diff --git a/testing/ef_tests/Makefile b/testing/ef_tests/Makefile index 0ead9d00472..724990cbecc 100644 --- a/testing/ef_tests/Makefile +++ b/testing/ef_tests/Makefile @@ -1,6 +1,6 @@ # To download/extract nightly tests, run: # CONSENSUS_SPECS_TEST_VERSION=nightly make -CONSENSUS_SPECS_TEST_VERSION ?= v1.6.0-beta.1 +CONSENSUS_SPECS_TEST_VERSION ?= v1.6.1 REPO_NAME := consensus-spec-tests OUTPUT_DIR := ./$(REPO_NAME) diff --git a/testing/ef_tests/check_all_files_accessed.py b/testing/ef_tests/check_all_files_accessed.py index 1f70881a887..4f278916db0 100755 --- a/testing/ef_tests/check_all_files_accessed.py +++ b/testing/ef_tests/check_all_files_accessed.py @@ -51,7 +51,6 @@ "tests/.*/fulu/ssz_static/MatrixEntry/.*", # EIP-7916 is still in draft and hasn't been implemented yet https://eips.ethereum.org/EIPS/eip-7916 "tests/general/phase0/ssz_generic/progressive_bitlist", - "tests/general/phase0/ssz_generic/basic_progressive_list", "tests/general/phase0/ssz_generic/containers/.*/ProgressiveBitsStruct.*", "tests/general/phase0/ssz_generic/containers/.*/ProgressiveTestStruct.*", "tests/general/phase0/ssz_generic/progressive_containers/.*", diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index 8742f8a1409..a4c6dd24b9f 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -10,7 +10,7 @@ use ssz_derive::{Decode, Encode}; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; use types::typenum::*; -use types::{BitList, BitVector, FixedVector, ForkName, VariableList, Vector}; +use types::{BitList, BitVector, FixedVector, ForkName, ProgressiveList, VariableList, Vector}; #[derive(Debug, Clone, Deserialize)] #[context_deserialize(ForkName)] @@ -157,6 +157,17 @@ impl Case for SszGeneric { [length => typenum] )?; } + "basic_progressive_list" => { + let elem_ty = parts[1]; + + type_dispatch!( + ssz_generic_test, + (&self.path, fork_name), + ProgressiveList, + <>, + [elem_ty => primitive_type] + )?; + } "bitlist" => { let mut limit = parts[1]; diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index a5b2ffada37..46eb61d7a3a 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -1135,6 +1135,8 @@ impl Handler for SszGenericHandler { // Supported SSZ generic handlers pub struct BasicVector; type_name!(BasicVector, "basic_vector"); +pub struct BasicProgressiveList; +type_name!(BasicProgressiveList, "basic_progressive_list"); pub struct Bitlist; type_name!(Bitlist, "bitlist"); pub struct Bitvector; diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 089e4464cd7..6ccb906c728 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -733,6 +733,11 @@ fn ssz_generic() { SszGenericHandler::::default().run(); } +#[test] +fn ssz_generic_progressive() { + SszGenericHandler::::default().run(); +} + #[test] fn epoch_processing_justification_and_finalization() { EpochProcessingHandler::::default().run(); From 9e15231ba2c3e9f0a325d89bbf6bc78ce3431104 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 10 Dec 2025 16:48:12 +1100 Subject: [PATCH 2/9] Test runners for basic progressive containers and bitlists --- Cargo.lock | 25 +++++------- Cargo.toml | 4 ++ consensus/types/src/lib.rs | 1 + testing/ef_tests/Cargo.toml | 1 + testing/ef_tests/src/cases/ssz_generic.rs | 47 +++++++++++++++++++++-- testing/ef_tests/src/handler.rs | 4 ++ testing/ef_tests/tests/tests.rs | 2 + 7 files changed, 65 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 901ff659520..a5bf115961e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,7 +698,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -709,7 +709,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2856,6 +2856,7 @@ dependencies = [ "context_deserialize", "educe", "eth2_network_config", + "ethereum_hashing", "ethereum_ssz", "ethereum_ssz_derive", "execution_layer", @@ -3118,7 +3119,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3283,8 +3284,6 @@ dependencies = [ [[package]] name = "ethereum_ssz" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8cd8c4f47dfb947dbfe3cdf2945ae1da808dbedc592668658e827a12659ba1" dependencies = [ "alloy-primitives", "arbitrary", @@ -3300,8 +3299,6 @@ dependencies = [ [[package]] name = "ethereum_ssz_derive" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d247bc40823c365a62e572441a8f8b12df03f171713f06bc76180fcd56ab71" dependencies = [ "darling 0.20.11", "proc-macro2", @@ -4759,7 +4756,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi 0.5.2", "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -6344,7 +6341,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -7786,7 +7783,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -8873,7 +8870,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -9446,8 +9443,6 @@ dependencies = [ [[package]] name = "tree_hash" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db21caa355767db4fd6129876e5ae278a8699f4a6959b1e3e7aff610b532d52" dependencies = [ "alloy-primitives", "ethereum_hashing", @@ -9459,8 +9454,6 @@ dependencies = [ [[package]] name = "tree_hash_derive" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711cc655fcbb48384a87dc2bf641b991a15c5ad9afc3caa0b1ab1df3b436f70f" dependencies = [ "darling 0.21.3", "proc-macro2", @@ -10209,7 +10202,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9e388fed841..157ef556020 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -288,3 +288,7 @@ quick-protobuf = { git = "https://github.com/sigp/quick-protobuf.git", rev = "68 # FIXME(sproul): REMOVE patch # milhouse = { path = "../milhouse" } milhouse = { git = "https://github.com/sigp/milhouse", branch = "progressive-list" } +ethereum_ssz = { path = "../packages/ethereum_ssz/ssz" } +ethereum_ssz_derive = { path = "../packages/ethereum_ssz/ssz_derive" } +tree_hash = { path = "../packages/tree_hash/tree_hash" } +tree_hash_derive = { path = "../packages/tree_hash/tree_hash_derive" } diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 9d02f71a3ee..2663eda38fb 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -174,5 +174,6 @@ pub use bls::{ pub use context_deserialize::{ContextDeserialize, context_deserialize}; pub use fixed_bytes::FixedBytesExtended; pub use milhouse::{self, List, ProgressiveList, Vector}; +pub use ssz::ProgressiveBitList; pub use ssz_types::{BitList, BitVector, FixedVector, VariableList, typenum, typenum::Unsigned}; pub use superstruct::superstruct; diff --git a/testing/ef_tests/Cargo.toml b/testing/ef_tests/Cargo.toml index 581785e2a97..17ad777699a 100644 --- a/testing/ef_tests/Cargo.toml +++ b/testing/ef_tests/Cargo.toml @@ -19,6 +19,7 @@ compare_fields = { workspace = true } context_deserialize = { workspace = true } educe = { workspace = true } eth2_network_config = { workspace = true } +ethereum_hashing = { workspace = true } # FIXME(sproul): remove ethereum_ssz = { workspace = true } ethereum_ssz_derive = { workspace = true } execution_layer = { workspace = true } diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index a4c6dd24b9f..c632439bc7e 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -8,9 +8,13 @@ use context_deserialize::{ContextDeserialize, context_deserialize}; use serde::{Deserialize, Deserializer, de::Error as SerdeError}; use ssz_derive::{Decode, Encode}; use tree_hash::TreeHash; +use tree_hash::{PackedEncoding, ProgressiveMerkleHasher, TreeHashType}; use tree_hash_derive::TreeHash; use types::typenum::*; -use types::{BitList, BitVector, FixedVector, ForkName, ProgressiveList, VariableList, Vector}; +use types::{ + BitList, BitVector, FixedVector, ForkName, Hash256, ProgressiveBitList, ProgressiveList, + VariableList, Vector, +}; #[derive(Debug, Clone, Deserialize)] #[context_deserialize(ForkName)] @@ -111,8 +115,7 @@ macro_rules! type_dispatch { "VarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* VarTestStruct>, $($rest)*), "ComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ComplexTestStruct>, $($rest)*), "BitsStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* BitsStruct>, $($rest)*), - // EIP-7916 is still in draft and hasn't been implemented yet https://eips.ethereum.org/EIPS/eip-7916 - "ProgressiveTestStruct" | "ProgressiveBitsStruct" => Err(Error::SkippedKnownFailure), + "ProgressiveSingleFieldContainerTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveSingleFieldContainerTestStruct>, $($rest)*), _ => Err(Error::FailedToParseTest(format!("unsupported: {}", $value))), } }; @@ -195,6 +198,14 @@ impl Case for SszGeneric { [length => typenum] )?; } + "progressive_bitlist" => { + type_dispatch!( + ssz_generic_test, + (&self.path, fork_name), + ProgressiveBitList, + <>, + )?; + } "boolean" => { ssz_generic_test::(&self.path, fork_name)?; } @@ -220,6 +231,22 @@ impl Case for SszGeneric { [type_name => test_container] )?; } + "progressive_containers" => { + let type_name = parts[0]; + + // FIXME(sproul): delete + if type_name != "ProgressiveSingleFieldContainerTestStruct" { + return Ok(()); + } + + type_dispatch!( + ssz_generic_test, + (&self.path, fork_name), + _, + <>, + [type_name => test_container] + )?; + } _ => panic!("unsupported handler: {}", self.handler_name), } Ok(()) @@ -321,6 +348,20 @@ struct BitsStruct { E: BitVector, } +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[tree_hash(struct_behaviour = "progressive_container", active_fields(1))] +#[context_deserialize(ForkName)] +struct ProgressiveSingleFieldContainerTestStruct { + A: u8, +} + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[tree_hash(struct_behaviour = "progressive_container", active_fields(1))] +#[context_deserialize(ForkName)] +struct ProgressiveSingleListContainerTestStruct { + C: ProgressiveBitList, +} + fn byte_list_from_hex_str<'de, D, N: Unsigned>( deserializer: D, ) -> Result, D::Error> diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index 46eb61d7a3a..15ff0c70e57 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -1141,9 +1141,13 @@ pub struct Bitlist; type_name!(Bitlist, "bitlist"); pub struct Bitvector; type_name!(Bitvector, "bitvector"); +pub struct ProgressiveBitlist; +type_name!(ProgressiveBitlist, "progressive_bitlist"); pub struct Boolean; type_name!(Boolean, "boolean"); pub struct Uints; type_name!(Uints, "uints"); pub struct Containers; type_name!(Containers, "containers"); +pub struct ProgressiveContainers; +type_name!(ProgressiveContainers, "progressive_containers"); diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 6ccb906c728..4504e366dbb 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -736,6 +736,8 @@ fn ssz_generic() { #[test] fn ssz_generic_progressive() { SszGenericHandler::::default().run(); + SszGenericHandler::::default().run(); + SszGenericHandler::::default().run(); } #[test] From fffd203cc5156cda0bba4a27100d894ed93c7ccd Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 18 Dec 2025 21:50:02 +1100 Subject: [PATCH 3/9] Rest of the progressive container tests --- Cargo.lock | 1 - Cargo.toml | 3 +- testing/ef_tests/src/cases/ssz_generic.rs | 76 ++++++++++++++++++++--- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5bf115961e..1e9e774f6c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5857,7 +5857,6 @@ dependencies = [ [[package]] name = "milhouse" version = "0.9.0" -source = "git+https://github.com/sigp/milhouse?branch=progressive-list#52bae1f50da93519cfb4ec31f7dab19659be4d14" dependencies = [ "alloy-primitives", "arbitrary", diff --git a/Cargo.toml b/Cargo.toml index 157ef556020..37d07d467f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,8 +286,7 @@ debug = true [patch.crates-io] quick-protobuf = { git = "https://github.com/sigp/quick-protobuf.git", rev = "681f413312404ab6e51f0b46f39b0075c6f4ebfd" } # FIXME(sproul): REMOVE patch -# milhouse = { path = "../milhouse" } -milhouse = { git = "https://github.com/sigp/milhouse", branch = "progressive-list" } +milhouse = { path = "../milhouse" } ethereum_ssz = { path = "../packages/ethereum_ssz/ssz" } ethereum_ssz_derive = { path = "../packages/ethereum_ssz/ssz_derive" } tree_hash = { path = "../packages/tree_hash/tree_hash" } diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index c632439bc7e..ca42ac1d1d4 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -8,14 +8,16 @@ use context_deserialize::{ContextDeserialize, context_deserialize}; use serde::{Deserialize, Deserializer, de::Error as SerdeError}; use ssz_derive::{Decode, Encode}; use tree_hash::TreeHash; -use tree_hash::{PackedEncoding, ProgressiveMerkleHasher, TreeHashType}; use tree_hash_derive::TreeHash; use types::typenum::*; use types::{ - BitList, BitVector, FixedVector, ForkName, Hash256, ProgressiveBitList, ProgressiveList, + BitList, BitVector, FixedVector, ForkName, List, ProgressiveBitList, ProgressiveList, VariableList, Vector, }; +type U1280 = op!(U128 * U10); +type U1281 = op!(U1280 + U1); + #[derive(Debug, Clone, Deserialize)] #[context_deserialize(ForkName)] struct Metadata { @@ -115,7 +117,12 @@ macro_rules! type_dispatch { "VarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* VarTestStruct>, $($rest)*), "ComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ComplexTestStruct>, $($rest)*), "BitsStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* BitsStruct>, $($rest)*), + "ProgressiveBitsStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveBitsStruct>, $($rest)*), "ProgressiveSingleFieldContainerTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveSingleFieldContainerTestStruct>, $($rest)*), + "ProgressiveSingleListContainerTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveSingleListContainerTestStruct>, $($rest)*), + "ProgressiveVarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveVarTestStruct>, $($rest)*), + "ProgressiveComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveComplexTestStruct>, $($rest)*), + "ProgressiveTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveTestStruct>, $($rest)*), _ => Err(Error::FailedToParseTest(format!("unsupported: {}", $value))), } }; @@ -234,11 +241,6 @@ impl Case for SszGeneric { "progressive_containers" => { let type_name = parts[0]; - // FIXME(sproul): delete - if type_name != "ProgressiveSingleFieldContainerTestStruct" { - return Ok(()); - } - type_dispatch!( ssz_generic_test, (&self.path, fork_name), @@ -338,6 +340,15 @@ struct ComplexTestStruct { G: Vector, } +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[context_deserialize(ForkName)] +struct ProgressiveTestStruct { + A: ProgressiveList, + B: ProgressiveList, + C: ProgressiveList, + D: ProgressiveList>, +} + #[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] #[context_deserialize(ForkName)] struct BitsStruct { @@ -348,6 +359,23 @@ struct BitsStruct { E: BitVector, } +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[context_deserialize(ForkName)] +struct ProgressiveBitsStruct { + A: BitVector, + B: BitList, + C: ProgressiveBitList, + D: BitVector, + E: BitList, + F: ProgressiveBitList, + G: BitVector, + H: BitList, + I: ProgressiveBitList, + J: BitVector, + K: BitList, + L: ProgressiveBitList, +} + #[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] #[tree_hash(struct_behaviour = "progressive_container", active_fields(1))] #[context_deserialize(ForkName)] @@ -356,12 +384,44 @@ struct ProgressiveSingleFieldContainerTestStruct { } #[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] -#[tree_hash(struct_behaviour = "progressive_container", active_fields(1))] +#[tree_hash( + struct_behaviour = "progressive_container", + active_fields(0, 0, 0, 0, 1) +)] #[context_deserialize(ForkName)] struct ProgressiveSingleListContainerTestStruct { C: ProgressiveBitList, } +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[tree_hash( + struct_behaviour = "progressive_container", + active_fields(1, 0, 1, 0, 1) +)] +#[context_deserialize(ForkName)] +struct ProgressiveVarTestStruct { + A: u8, + B: List, + C: ProgressiveBitList, +} + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[tree_hash( + struct_behaviour = "progressive_container", + active_fields(1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1) +)] +#[context_deserialize(ForkName)] +struct ProgressiveComplexTestStruct { + A: u8, + B: List, + C: ProgressiveBitList, + D: ProgressiveList, + E: ProgressiveList, + F: ProgressiveList>, + G: List, + H: ProgressiveList, +} + fn byte_list_from_hex_str<'de, D, N: Unsigned>( deserializer: D, ) -> Result, D::Error> From 30289cd750eaedf6fbd79ac17a971e7913dd8320 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 18 Dec 2025 21:54:31 +1100 Subject: [PATCH 4/9] Remove path patches --- Cargo.lock | 21 +++++++++++++-------- Cargo.toml | 10 +++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e9e774f6c6..0ea1bdb0119 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,7 +698,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -709,7 +709,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -3119,7 +3119,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3284,6 +3284,7 @@ dependencies = [ [[package]] name = "ethereum_ssz" version = "0.10.0" +source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e" dependencies = [ "alloy-primitives", "arbitrary", @@ -3299,6 +3300,7 @@ dependencies = [ [[package]] name = "ethereum_ssz_derive" version = "0.10.0" +source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e" dependencies = [ "darling 0.20.11", "proc-macro2", @@ -4756,7 +4758,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi 0.5.2", "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -5857,6 +5859,7 @@ dependencies = [ [[package]] name = "milhouse" version = "0.9.0" +source = "git+https://github.com/sigp/milhouse?branch=progressive-list#556e7bb1f18af5c0ffeccc4ecaa9cd52ebb9003c" dependencies = [ "alloy-primitives", "arbitrary", @@ -6340,7 +6343,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -7782,7 +7785,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -8869,7 +8872,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -9442,6 +9445,7 @@ dependencies = [ [[package]] name = "tree_hash" version = "0.12.0" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417" dependencies = [ "alloy-primitives", "ethereum_hashing", @@ -9453,6 +9457,7 @@ dependencies = [ [[package]] name = "tree_hash_derive" version = "0.12.0" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417" dependencies = [ "darling 0.21.3", "proc-macro2", @@ -10201,7 +10206,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 37d07d467f4..2b988524cd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,8 +286,8 @@ debug = true [patch.crates-io] quick-protobuf = { git = "https://github.com/sigp/quick-protobuf.git", rev = "681f413312404ab6e51f0b46f39b0075c6f4ebfd" } # FIXME(sproul): REMOVE patch -milhouse = { path = "../milhouse" } -ethereum_ssz = { path = "../packages/ethereum_ssz/ssz" } -ethereum_ssz_derive = { path = "../packages/ethereum_ssz/ssz_derive" } -tree_hash = { path = "../packages/tree_hash/tree_hash" } -tree_hash_derive = { path = "../packages/tree_hash/tree_hash_derive" } +milhouse = { git = "https://github.com/sigp/milhouse", branch = "progressive-list" } +ethereum_ssz = { git = "https://github.com/sigp/ethereum_ssz", branch = "progressive" } +ethereum_ssz_derive = { git = "https://github.com/sigp/ethereum_ssz", branch = "progressive" } +tree_hash = { git = "https://github.com/sigp/tree_hash", branch = "progressive" } +tree_hash_derive = { git = "https://github.com/sigp/tree_hash", branch = "progressive" } From 6b5d87869b1e8a3c022a96fd51fffa557ba83fb6 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 12 Jan 2026 16:11:46 +1100 Subject: [PATCH 5/9] Compatible union tests --- Cargo.lock | 24 ++++++------ testing/ef_tests/src/cases/ssz_generic.rs | 45 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ea1bdb0119..3520d3d8be6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1953,7 +1953,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -3119,7 +3119,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3284,7 +3284,7 @@ dependencies = [ [[package]] name = "ethereum_ssz" version = "0.10.0" -source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e" +source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#ed6332b0572f18bf285d2acdfc6932e1b9d274ef" dependencies = [ "alloy-primitives", "arbitrary", @@ -3300,7 +3300,7 @@ dependencies = [ [[package]] name = "ethereum_ssz_derive" version = "0.10.0" -source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e" +source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#ed6332b0572f18bf285d2acdfc6932e1b9d274ef" dependencies = [ "darling 0.20.11", "proc-macro2", @@ -4758,7 +4758,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi 0.5.2", "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -6343,7 +6343,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -7263,7 +7263,7 @@ dependencies = [ "once_cell", "socket2 0.6.1", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -7785,7 +7785,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -8872,7 +8872,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -9445,7 +9445,7 @@ dependencies = [ [[package]] name = "tree_hash" version = "0.12.0" -source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8" dependencies = [ "alloy-primitives", "ethereum_hashing", @@ -9457,7 +9457,7 @@ dependencies = [ [[package]] name = "tree_hash_derive" version = "0.12.0" -source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8" dependencies = [ "darling 0.21.3", "proc-macro2", @@ -10206,7 +10206,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index ca42ac1d1d4..bd1567fbfca 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -123,6 +123,9 @@ macro_rules! type_dispatch { "ProgressiveVarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveVarTestStruct>, $($rest)*), "ProgressiveComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveComplexTestStruct>, $($rest)*), "ProgressiveTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveTestStruct>, $($rest)*), + "CompatibleUnionA" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionA>, $($rest)*), + "CompatibleUnionBC" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionBC>, $($rest)*), + "CompatibleUnionABCA" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionABCA>, $($rest)*), _ => Err(Error::FailedToParseTest(format!("unsupported: {}", $value))), } }; @@ -422,6 +425,48 @@ struct ProgressiveComplexTestStruct { H: ProgressiveList, } +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[ssz(enum_behaviour = "compatible_union")] +#[tree_hash(enum_behaviour = "compatible_union")] +#[context_deserialize(ForkName)] +enum CompatibleUnionA { + #[ssz(selector = "1")] + #[tree_hash(selector = "1")] + ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct), +} + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[ssz(enum_behaviour = "compatible_union")] +#[tree_hash(enum_behaviour = "compatible_union")] +#[context_deserialize(ForkName)] +enum CompatibleUnionBC { + #[ssz(selector = "2")] + #[tree_hash(selector = "2")] + ProgressiveSingleListContainerTestStruct(ProgressiveSingleListContainerTestStruct), + #[ssz(selector = "3")] + #[tree_hash(selector = "3")] + ProgressiveVarTestStruct(ProgressiveVarTestStruct), +} + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[ssz(enum_behaviour = "compatible_union")] +#[tree_hash(enum_behaviour = "compatible_union")] +#[context_deserialize(ForkName)] +enum CompatibleUnionABCA { + #[ssz(selector = "1")] + #[tree_hash(selector = "1")] + A1(ProgressiveSingleFieldContainerTestStruct), + #[ssz(selector = "2")] + #[tree_hash(selector = "2")] + B1(ProgressiveSingleListContainerTestStruct), + #[ssz(selector = "3")] + #[tree_hash(selector = "3")] + C1(ProgressiveVarTestStruct), + #[ssz(selector = "4")] + #[tree_hash(selector = "4")] + A2(ProgressiveSingleFieldContainerTestStruct), +} + fn byte_list_from_hex_str<'de, D, N: Unsigned>( deserializer: D, ) -> Result, D::Error> From 9aad3c600455c33670f038b71de9036c92ad3673 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 12 Jan 2026 16:32:51 +1100 Subject: [PATCH 6/9] Passing on v1.7.1-alpha.1 --- testing/ef_tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/ef_tests/Makefile b/testing/ef_tests/Makefile index 724990cbecc..0c6371f8253 100644 --- a/testing/ef_tests/Makefile +++ b/testing/ef_tests/Makefile @@ -1,6 +1,6 @@ # To download/extract nightly tests, run: # CONSENSUS_SPECS_TEST_VERSION=nightly make -CONSENSUS_SPECS_TEST_VERSION ?= v1.6.1 +CONSENSUS_SPECS_TEST_VERSION ?= v1.7.0-alpha.1 REPO_NAME := consensus-spec-tests OUTPUT_DIR := ./$(REPO_NAME) From ecd207f421ac02446254fbda038d69e14b0a426b Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 13 Jan 2026 12:47:43 +1100 Subject: [PATCH 7/9] Remove selector attribute duplication! Yay! --- Cargo.lock | 18 +++++++++--------- testing/ef_tests/src/cases/ssz_generic.rs | 7 ------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6a696496f1..104061df5f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3057,7 +3057,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -4675,7 +4675,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -6270,7 +6270,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -7179,7 +7179,7 @@ dependencies = [ "once_cell", "socket2 0.6.1", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -7674,7 +7674,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -7687,7 +7687,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -8753,7 +8753,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -9324,7 +9324,7 @@ dependencies = [ [[package]] name = "tree_hash" version = "0.12.0" -source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#4f7349913ba9ac8cce7112b2279364f8fcac1f5d" dependencies = [ "alloy-primitives", "ethereum_hashing", @@ -9336,7 +9336,7 @@ dependencies = [ [[package]] name = "tree_hash_derive" version = "0.12.0" -source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8" +source = "git+https://github.com/sigp/tree_hash?branch=progressive#4f7349913ba9ac8cce7112b2279364f8fcac1f5d" dependencies = [ "darling 0.21.3", "proc-macro2", diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index ec301112341..e394a69437e 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -431,7 +431,6 @@ struct ProgressiveComplexTestStruct { #[context_deserialize(ForkName)] enum CompatibleUnionA { #[ssz(selector = "1")] - #[tree_hash(selector = "1")] ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct), } @@ -441,10 +440,8 @@ enum CompatibleUnionA { #[context_deserialize(ForkName)] enum CompatibleUnionBC { #[ssz(selector = "2")] - #[tree_hash(selector = "2")] ProgressiveSingleListContainerTestStruct(ProgressiveSingleListContainerTestStruct), #[ssz(selector = "3")] - #[tree_hash(selector = "3")] ProgressiveVarTestStruct(ProgressiveVarTestStruct), } @@ -454,16 +451,12 @@ enum CompatibleUnionBC { #[context_deserialize(ForkName)] enum CompatibleUnionABCA { #[ssz(selector = "1")] - #[tree_hash(selector = "1")] A1(ProgressiveSingleFieldContainerTestStruct), #[ssz(selector = "2")] - #[tree_hash(selector = "2")] B1(ProgressiveSingleListContainerTestStruct), #[ssz(selector = "3")] - #[tree_hash(selector = "3")] C1(ProgressiveVarTestStruct), #[ssz(selector = "4")] - #[tree_hash(selector = "4")] A2(ProgressiveSingleFieldContainerTestStruct), } From be9d697ad9798d0695e48c433000e0ff6b4445fe Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 13 Feb 2026 05:29:36 +1100 Subject: [PATCH 8/9] Fix Bitfield type inference --- consensus/state_processing/src/per_block_processing/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/consensus/state_processing/src/per_block_processing/tests.rs b/consensus/state_processing/src/per_block_processing/tests.rs index 739717b33ff..ca359c93c75 100644 --- a/consensus/state_processing/src/per_block_processing/tests.rs +++ b/consensus/state_processing/src/per_block_processing/tests.rs @@ -495,7 +495,9 @@ async fn invalid_attestation_bad_aggregation_bitfield_len() { .next() .unwrap() .aggregation_bits_base_mut() - .unwrap() = Bitfield::with_capacity(spec.target_committee_size).unwrap(); + .unwrap() = + Bitfield::::MaxValidatorsPerCommittee>>::with_capacity(spec.target_committee_size) + .unwrap(); let mut ctxt = ConsensusContext::new(state.slot()); let result = process_operations::process_attestations( From 827ff953bcc5de14263a251ea28249fc54c2f57c Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 13 Feb 2026 21:10:34 +1100 Subject: [PATCH 9/9] Enable all ssz tests --- testing/ef_tests/check_all_files_accessed.py | 6 -- testing/ef_tests/src/cases/ssz_generic.rs | 71 +++++++++++++++++++- testing/ef_tests/src/handler.rs | 2 + testing/ef_tests/tests/tests.rs | 1 + 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/testing/ef_tests/check_all_files_accessed.py b/testing/ef_tests/check_all_files_accessed.py index 4b016dc0b0a..fd015414cfc 100755 --- a/testing/ef_tests/check_all_files_accessed.py +++ b/testing/ef_tests/check_all_files_accessed.py @@ -66,12 +66,6 @@ "tests/.*/gloas/ssz_static/ExecutionPayloadHeader/.*", # ForkChoiceNode is internal to fork choice and probably doesn't need SSZ tests. "tests/.*/gloas/ssz_static/ForkChoiceNode/.*", - # EIP-7916 is still in draft and hasn't been implemented yet https://eips.ethereum.org/EIPS/eip-7916 - "tests/general/phase0/ssz_generic/progressive_bitlist", - "tests/general/phase0/ssz_generic/containers/.*/ProgressiveBitsStruct.*", - "tests/general/phase0/ssz_generic/containers/.*/ProgressiveTestStruct.*", - "tests/general/phase0/ssz_generic/progressive_containers/.*", - "tests/general/phase0/ssz_generic/compatible_unions/.*", # Ignore full epoch tests for now (just test the sub-transitions). "tests/.*/.*/epoch_processing/.*/pre_epoch.ssz_snappy", "tests/.*/.*/epoch_processing/.*/post_epoch.ssz_snappy", diff --git a/testing/ef_tests/src/cases/ssz_generic.rs b/testing/ef_tests/src/cases/ssz_generic.rs index e394a69437e..429be3a9aec 100644 --- a/testing/ef_tests/src/cases/ssz_generic.rs +++ b/testing/ef_tests/src/cases/ssz_generic.rs @@ -7,6 +7,7 @@ use crate::decode::{context_yaml_decode_file, log_file_access, snappy_decode_fil use context_deserialize::{ContextDeserialize, context_deserialize}; use milhouse::{List, ProgressiveList, Vector}; use serde::{Deserialize, Deserializer, de::Error as SerdeError}; +use serde_json::Value as JsonValue; use ssz::ProgressiveBitList; use ssz_derive::{Decode, Encode}; use ssz_types::{BitList, BitVector, FixedVector, VariableList}; @@ -15,6 +16,43 @@ use tree_hash_derive::TreeHash; use typenum::*; use types::ForkName; +/// Helper struct for deserializing compatible unions from `{selector, data}` YAML format. +#[derive(Deserialize)] +struct CompatibleUnionYaml { + selector: u8, + data: JsonValue, +} + +/// Implements `Deserialize` for compatible union types to handle the EF test YAML format. +/// +/// Deserialize into `CompatibleUnionYaml` which captures `selector` (`u8`) and +/// `data` (`JsonValue`). +/// Match on the selector to determine which variant to construct. +/// Deserialize the `data` field into the appropriate inner type. +macro_rules! impl_compatible_union_deserialize { + ($type:ty, { $($selector:literal => $variant:ident($inner:ty)),+ $(,)? }) => { + impl<'de> Deserialize<'de> for $type { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let yaml = CompatibleUnionYaml::deserialize(deserializer)?; + match yaml.selector { + $( + $selector => { + let inner: $inner = serde_json::from_value(yaml.data).map_err(D::Error::custom)?; + Ok(<$type>::$variant(inner)) + } + )+ + s => Err(D::Error::custom(format!( + "unknown selector {s} for {}", stringify!($type) + ))), + } + } + } + }; +} + type U1280 = op!(U128 * U10); type U1281 = op!(U1280 + U1); @@ -252,6 +290,17 @@ impl Case for SszGeneric { [type_name => test_container] )?; } + "compatible_unions" => { + let type_name = parts[0]; + + type_dispatch!( + ssz_generic_test, + (&self.path, fork_name), + _, + <>, + [type_name => test_container] + )?; + } _ => panic!("unsupported handler: {}", self.handler_name), } Ok(()) @@ -425,7 +474,7 @@ struct ProgressiveComplexTestStruct { H: ProgressiveList, } -#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)] #[ssz(enum_behaviour = "compatible_union")] #[tree_hash(enum_behaviour = "compatible_union")] #[context_deserialize(ForkName)] @@ -434,7 +483,11 @@ enum CompatibleUnionA { ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct), } -#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +impl_compatible_union_deserialize!(CompatibleUnionA, { + 1 => ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct), +}); + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)] #[ssz(enum_behaviour = "compatible_union")] #[tree_hash(enum_behaviour = "compatible_union")] #[context_deserialize(ForkName)] @@ -445,7 +498,12 @@ enum CompatibleUnionBC { ProgressiveVarTestStruct(ProgressiveVarTestStruct), } -#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)] +impl_compatible_union_deserialize!(CompatibleUnionBC, { + 2 => ProgressiveSingleListContainerTestStruct(ProgressiveSingleListContainerTestStruct), + 3 => ProgressiveVarTestStruct(ProgressiveVarTestStruct), +}); + +#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)] #[ssz(enum_behaviour = "compatible_union")] #[tree_hash(enum_behaviour = "compatible_union")] #[context_deserialize(ForkName)] @@ -460,6 +518,13 @@ enum CompatibleUnionABCA { A2(ProgressiveSingleFieldContainerTestStruct), } +impl_compatible_union_deserialize!(CompatibleUnionABCA, { + 1 => A1(ProgressiveSingleFieldContainerTestStruct), + 2 => B1(ProgressiveSingleListContainerTestStruct), + 3 => C1(ProgressiveVarTestStruct), + 4 => A2(ProgressiveSingleFieldContainerTestStruct), +}); + fn byte_list_from_hex_str<'de, D, N: Unsigned>( deserializer: D, ) -> Result, D::Error> diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index 80dba59c291..5747800e731 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -1198,3 +1198,5 @@ pub struct Containers; type_name!(Containers, "containers"); pub struct ProgressiveContainers; type_name!(ProgressiveContainers, "progressive_containers"); +pub struct CompatibleUnions; +type_name!(CompatibleUnions, "compatible_unions"); diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 934ae6b35e3..68ab4f1eacc 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -856,6 +856,7 @@ fn ssz_generic_progressive() { SszGenericHandler::::default().run(); SszGenericHandler::::default().run(); SszGenericHandler::::default().run(); + SszGenericHandler::::default().run(); } #[test]