Skip to content
48 changes: 12 additions & 36 deletions crates/core/src/signeddata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl SignedData for SignedVoluntaryExit {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
Ok(hash_root(&self.0.message))
Ok(self.0.message_root())
}
}

Expand Down Expand Up @@ -668,12 +668,10 @@ impl SignedData for VersionedSignedValidatorRegistration {

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
match self.0.version {
versioned::BuilderVersion::V1 => {
let Some(v1) = self.0.v1.as_ref() else {
return Err(SignedDataError::MissingV1Registration);
};
Ok(hash_root(&v1.message))
}
versioned::BuilderVersion::V1 => self
.0
.message_root()
.ok_or(SignedDataError::MissingV1Registration),
versioned::BuilderVersion::Unknown => Err(SignedDataError::UnknownVersion),
}
}
Expand Down Expand Up @@ -745,7 +743,7 @@ impl SignedData for SignedRandao {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
Ok(hash_root(&self.0))
Ok(self.0.message_root())
}
}

Expand Down Expand Up @@ -788,7 +786,7 @@ impl SignedData for BeaconCommitteeSelection {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
Ok(hash_root(&self.0.slot))
Ok(self.0.message_root())
}
}

Expand Down Expand Up @@ -824,12 +822,7 @@ impl SignedData for SyncCommitteeSelection {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
let data = altair::SyncAggregatorSelectionData {
slot: self.0.slot,
subcommittee_index: self.0.subcommittee_index,
};

Ok(hash_root(&data))
Ok(self.0.message_root())
}
}

Expand Down Expand Up @@ -950,19 +943,7 @@ impl SignedData for VersionedSignedAggregateAndProof {
return Err(SignedDataError::UnknownVersion);
}

Ok(match &self.0.aggregate_and_proof {
versioned::SignedAggregateAndProofPayload::Phase0(payload)
| versioned::SignedAggregateAndProofPayload::Altair(payload)
| versioned::SignedAggregateAndProofPayload::Bellatrix(payload)
| versioned::SignedAggregateAndProofPayload::Capella(payload)
| versioned::SignedAggregateAndProofPayload::Deneb(payload) => {
hash_root(&payload.message)
}
versioned::SignedAggregateAndProofPayload::Electra(payload)
| versioned::SignedAggregateAndProofPayload::Fulu(payload) => {
hash_root(&payload.message)
}
})
self.0.message_root().ok_or(SignedDataError::UnknownVersion)
}
}

Expand Down Expand Up @@ -1043,7 +1024,7 @@ impl SignedData for SignedSyncMessage {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
Ok(self.0.beacon_block_root)
Ok(self.0.message_root())
}
}

Expand Down Expand Up @@ -1079,12 +1060,7 @@ impl SignedData for SyncContributionAndProof {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
let data = altair::SyncAggregatorSelectionData {
slot: self.0.contribution.slot,
subcommittee_index: self.0.contribution.subcommittee_index,
};

Ok(hash_root(&data))
Ok(self.0.selection_proof_message_root())
}
}

Expand Down Expand Up @@ -1120,7 +1096,7 @@ impl SignedData for SignedSyncContributionAndProof {
}

fn message_root(&self) -> Result<[u8; 32], SignedDataError> {
Ok(hash_root(&self.0.message))
Ok(self.0.message_root())
}
}

Expand Down
Loading
Loading