Skip to content

Feature gate arbitrary crate in the consensus types crate #7743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ malloc_utils = { path = "common/malloc_utils" }
maplit = "1"
merkle_proof = { path = "consensus/merkle_proof" }
metrics = { path = "common/metrics" }
milhouse = "0.6"
milhouse = { version = "0.7", default-features = false }
mockall = "0.13"
mockall_double = "0.3"
mockito = "1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.84.0-bullseye AS builder
FROM rust:1.88.0-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . lighthouse
ARG FEATURES
Expand Down
24 changes: 14 additions & 10 deletions consensus/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ default = ["sqlite", "legacy-arith"]
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
legacy-arith = []
sqlite = ["dep:rusqlite"]
# The `arbitrary-fuzz` feature is a no-op provided for backwards compatibility.
# For simplicity `Arbitrary` is now derived regardless of the feature's presence.
arbitrary-fuzz = []
arbitrary = [
"dep:arbitrary",
"bls/arbitrary",
"ethereum_ssz/arbitrary",
"milhouse/arbitrary",
"ssz_types/arbitrary",
"swap_or_not_shuffle/arbitrary",
]
arbitrary-fuzz = ["arbitrary"]
portable = ["bls/supranational-portable"]

[dependencies]
alloy-primitives = { workspace = true }
alloy-rlp = { version = "0.3.4", features = ["derive"] }
# The arbitrary dependency is enabled by default since Capella to avoid complexity introduced by
# `AbstractExecPayload`
arbitrary = { workspace = true, features = ["derive"] }
bls = { workspace = true, features = ["arbitrary"] }
arbitrary = { workspace = true, features = ["derive"], optional = true }
bls = { workspace = true }
compare_fields = { workspace = true }
compare_fields_derive = { workspace = true }
context_deserialize = { workspace = true }
Expand All @@ -29,7 +33,7 @@ derivative = { workspace = true }
eth2_interop_keypairs = { path = "../../common/eth2_interop_keypairs" }
ethereum_hashing = { workspace = true }
ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true, features = ["arbitrary"] }
ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
fixed_bytes = { workspace = true }
hex = { workspace = true }
Expand All @@ -52,9 +56,9 @@ serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
smallvec = { workspace = true }
ssz_types = { workspace = true, features = ["arbitrary"] }
ssz_types = { workspace = true }
superstruct = { workspace = true }
swap_or_not_shuffle = { workspace = true, features = ["arbitrary"] }
swap_or_not_shuffle = { workspace = true }
tempfile = { workspace = true }
test_random_derive = { path = "../../common/test_random_derive" }
tracing = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion consensus/types/src/activation_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{ChainSpec, Epoch, Validator};
use std::collections::BTreeSet;

/// Activation queue computed during epoch processing for use in the *next* epoch.
#[derive(Debug, PartialEq, Eq, Default, Clone, arbitrary::Arbitrary)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, PartialEq, Eq, Default, Clone)]
pub struct ActivationQueue {
/// Validators represented by `(activation_eligibility_epoch, index)` in sorted order.
///
Expand Down
17 changes: 11 additions & 6 deletions consensus/types/src/aggregate_and_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use tree_hash_derive::TreeHash;
variants(Base, Electra),
variant_attributes(
derive(
arbitrary::Arbitrary,
Debug,
Clone,
PartialEq,
Expand All @@ -29,23 +28,29 @@ use tree_hash_derive::TreeHash;
),
context_deserialize(ForkName),
serde(bound = "E: EthSpec"),
arbitrary(bound = "E: EthSpec"),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec"),
),
),
ref_attributes(
derive(Debug, PartialEq, TreeHash, Serialize,),
derive(Debug, PartialEq, TreeHash, Serialize),
serde(untagged, bound = "E: EthSpec"),
tree_hash(enum_behaviour = "transparent")
),
map_ref_into(AttestationRef)
)]
#[derive(
arbitrary::Arbitrary, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, TreeHash,
#[cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, TreeHash)]
#[serde(untagged)]
#[tree_hash(enum_behaviour = "transparent")]
#[ssz(enum_behaviour = "transparent")]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
#[arbitrary(bound = "E: EthSpec")]
pub struct AggregateAndProof<E: EthSpec> {
/// The index of the validator that created the attestation.
#[serde(with = "serde_utils::quoted_u64")]
Expand Down
25 changes: 11 additions & 14 deletions consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,31 @@ impl From<ssz_types::Error> for Error {
Encode,
TestRandom,
Derivative,
arbitrary::Arbitrary,
TreeHash,
),
context_deserialize(ForkName),
derivative(PartialEq, Hash(bound = "E: EthSpec")),
serde(bound = "E: EthSpec", deny_unknown_fields),
arbitrary(bound = "E: EthSpec"),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
)
),
ref_attributes(derive(TreeHash), tree_hash(enum_behaviour = "transparent")),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(
Debug,
Clone,
Serialize,
TreeHash,
Encode,
Derivative,
Deserialize,
arbitrary::Arbitrary,
PartialEq,
#[cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
)]
#[derive(Debug, Clone, Serialize, TreeHash, Encode, Derivative, Deserialize, PartialEq)]
#[serde(untagged)]
#[tree_hash(enum_behaviour = "transparent")]
#[ssz(enum_behaviour = "transparent")]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
#[arbitrary(bound = "E: EthSpec")]
pub struct Attestation<E: EthSpec> {
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
pub aggregation_bits: BitList<E::MaxValidatorsPerCommittee>,
Expand Down Expand Up @@ -601,6 +598,7 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>>
}
*/

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Debug,
Clone,
Expand All @@ -610,7 +608,6 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>>
Encode,
TestRandom,
Derivative,
arbitrary::Arbitrary,
TreeHash,
PartialEq,
)]
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/attestation_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use tree_hash_derive::TreeHash;
/// The data upon which an attestation is based.
///
/// Spec v0.12.1
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
arbitrary::Arbitrary,
Debug,
Clone,
PartialEq,
Expand Down
3 changes: 2 additions & 1 deletion consensus/types/src/attestation_duty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::*;
use serde::{Deserialize, Serialize};

#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
pub struct AttestationDuty {
/// The slot during which the attester must attest.
pub slot: Slot,
Expand Down
15 changes: 10 additions & 5 deletions consensus/types/src/attester_slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ use tree_hash_derive::TreeHash;
Decode,
TreeHash,
TestRandom,
arbitrary::Arbitrary
),
context_deserialize(ForkName),
derivative(PartialEq, Eq, Hash(bound = "E: EthSpec")),
serde(bound = "E: EthSpec"),
arbitrary(bound = "E: EthSpec")
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
),
),
ref_attributes(derive(Debug))
)]
#[derive(
Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative, arbitrary::Arbitrary,
#[cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
)]
#[derive(Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative)]
#[derivative(PartialEq, Eq, Hash(bound = "E: EthSpec"))]
#[serde(bound = "E: EthSpec", untagged)]
#[arbitrary(bound = "E: EthSpec")]
#[ssz(enum_behaviour = "transparent")]
#[tree_hash(enum_behaviour = "transparent")]
pub struct AttesterSlashing<E: EthSpec> {
Expand Down
15 changes: 10 additions & 5 deletions consensus/types/src/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ use self::indexed_attestation::IndexedAttestationBase;
TreeHash,
TestRandom,
Derivative,
arbitrary::Arbitrary
),
derivative(PartialEq, Hash(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")),
serde(
bound = "E: EthSpec, Payload: AbstractExecPayload<E>",
deny_unknown_fields
),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>"),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")
)
),
ref_attributes(
derive(Debug, PartialEq, TreeHash),
Expand All @@ -44,13 +47,15 @@ use self::indexed_attestation::IndexedAttestationBase;
map_ref_into(BeaconBlockBodyRef, BeaconBlock),
map_ref_mut_into(BeaconBlockBodyRefMut)
)]
#[derive(
Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative, arbitrary::Arbitrary,
#[cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")
)]
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)]
#[derivative(PartialEq, Hash(bound = "E: EthSpec"))]
#[serde(untagged)]
#[serde(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
#[arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
#[tree_hash(enum_behaviour = "transparent")]
#[ssz(enum_behaviour = "transparent")]
pub struct BeaconBlock<E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload<E>> {
Expand Down
17 changes: 12 additions & 5 deletions consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;
TreeHash,
TestRandom,
Derivative,
arbitrary::Arbitrary
),
derivative(PartialEq, Hash(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")),
serde(
bound = "E: EthSpec, Payload: AbstractExecPayload<E>",
deny_unknown_fields
),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>"),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>"),
),
context_deserialize(ForkName),
),
specific_variant_attributes(
Expand All @@ -62,12 +65,16 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Debug, Clone, Serialize, Deserialize, Derivative, TreeHash, arbitrary::Arbitrary)]
#[cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")
)]
#[derive(Debug, Clone, Serialize, Deserialize, Derivative, TreeHash)]
#[derivative(PartialEq, Hash(bound = "E: EthSpec"))]
#[serde(untagged)]
#[serde(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
#[tree_hash(enum_behaviour = "transparent")]
#[arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload<E>> {
pub randao_reveal: Signature,
pub eth1_data: Eth1Data,
Expand Down Expand Up @@ -128,7 +135,7 @@ pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPay
#[ssz(skip_serializing, skip_deserializing)]
#[tree_hash(skip_hashing)]
#[serde(skip)]
#[arbitrary(default)]
#[cfg_attr(feature = "arbitrary", arbitrary(default))]
pub _phantom: PhantomData<Payload>,
}

Expand Down
14 changes: 2 additions & 12 deletions consensus/types/src/beacon_block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,9 @@ use tree_hash_derive::TreeHash;
/// A header of a `BeaconBlock`.
///
/// Spec v0.12.1
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
arbitrary::Arbitrary,
Debug,
PartialEq,
Eq,
Hash,
Clone,
Serialize,
Deserialize,
Encode,
Decode,
TreeHash,
TestRandom,
Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom,
)]
#[context_deserialize(ForkName)]
pub struct BeaconBlockHeader {
Expand Down
3 changes: 2 additions & 1 deletion consensus/types/src/beacon_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl BeaconCommittee<'_> {
}
}

#[derive(arbitrary::Arbitrary, Default, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Default, Clone, Debug, PartialEq)]
pub struct OwnedBeaconCommittee {
pub slot: Slot,
pub index: CommitteeIndex,
Expand Down
Loading