Skip to content

Commit 148b89a

Browse files
authored
fix: resolve tree hash calculation for IndexedAttestation and Attestation types (#698)
* fix: resolve tree hash calculation for IndexedAttestation and Attestation types Fixed incorrect variant ordering in superstruct definitions that was causing tree hash mismatches for beacon blocks. The Electra variant must be listed first before Base variant to ensure proper deserialization and hash calculation. Changes made: - Reordered IndexedAttestation variants to list Electra before Base - Reordered Attestation variants to list Electra before Base - Added test case for slot 12557247 to verify tree hash calculation - Added reqwest and serde_json dependencies for the new test This resolves issues with beacon block hash verification where the calculated tree hash did not match the expected value. * fmt
1 parent eda05b3 commit 148b89a

File tree

4 files changed

+163
-28
lines changed

4 files changed

+163
-28
lines changed

Cargo.lock

Lines changed: 102 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethereum/consensus-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ wasmtimer = "0.2.0"
3737
tokio = { version = "1", features = ["full"] }
3838
snap = "1"
3939
serde_yaml = "0.9.34"
40+
reqwest = { version = "0.11", features = ["json"] }
41+
serde_json = "1.0"

ethereum/consensus-core/src/types/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub struct AttesterSlashing<S: ConsensusSpec> {
277277
}
278278

279279
#[superstruct(
280-
variants(Base, Electra),
280+
variants(Electra, Base),
281281
variant_attributes(
282282
derive(Deserialize, Debug, Default, Encode, TreeHash, Clone,),
283283
serde(deny_unknown_fields),
@@ -288,13 +288,13 @@ pub struct AttesterSlashing<S: ConsensusSpec> {
288288
#[serde(untagged)]
289289
#[ssz(enum_behaviour = "transparent")]
290290
#[tree_hash(enum_behaviour = "transparent")]
291-
struct IndexedAttestation<S: ConsensusSpec> {
292-
#[serde(with = "quoted_u64_var_list")]
293-
#[superstruct(only(Base), partial_getter(rename = "attesting_indices_base"))]
294-
attesting_indices: VariableList<u64, S::MaxValidatorsPerCommittee>,
291+
pub struct IndexedAttestation<S: ConsensusSpec> {
295292
#[serde(with = "quoted_u64_var_list")]
296293
#[superstruct(only(Electra), partial_getter(rename = "attesting_indices_electra"))]
297294
attesting_indices: VariableList<u64, S::MaxValidatorsPerSlot>,
295+
#[serde(with = "quoted_u64_var_list")]
296+
#[superstruct(only(Base), partial_getter(rename = "attesting_indices_base"))]
297+
attesting_indices: VariableList<u64, S::MaxValidatorsPerCommittee>,
298298
data: AttestationData,
299299
signature: Signature,
300300
}
@@ -306,7 +306,7 @@ impl<S: ConsensusSpec> Default for IndexedAttestation<S> {
306306
}
307307

308308
#[superstruct(
309-
variants(Base, Electra),
309+
variants(Electra, Base),
310310
variant_attributes(
311311
derive(Deserialize, Debug, Encode, TreeHash, Clone,),
312312
serde(deny_unknown_fields),
@@ -318,10 +318,10 @@ impl<S: ConsensusSpec> Default for IndexedAttestation<S> {
318318
#[ssz(enum_behaviour = "transparent")]
319319
#[tree_hash(enum_behaviour = "transparent")]
320320
pub struct Attestation<S: ConsensusSpec> {
321-
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
322-
aggregation_bits: BitList<S::MaxValidatorsPerCommittee>,
323321
#[superstruct(only(Electra), partial_getter(rename = "aggregation_bits_electra"))]
324322
aggregation_bits: BitList<S::MaxValidatorsPerSlot>,
323+
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
324+
aggregation_bits: BitList<S::MaxValidatorsPerCommittee>,
325325
data: AttestationData,
326326
signature: Signature,
327327
#[superstruct(only(Electra))]

0 commit comments

Comments
 (0)