diff --git a/beacon_node/beacon_chain/src/state_transition.rs b/beacon_node/beacon_chain/src/state_transition.rs index 5b614234f8..0537ad1959 100644 --- a/beacon_node/beacon_chain/src/state_transition.rs +++ b/beacon_node/beacon_chain/src/state_transition.rs @@ -265,18 +265,11 @@ where .as_raw(), ) } - let attestation_message = { - let attestation_data_and_custody_bit = AttestationDataAndCustodyBit { - data: attestation.data.clone(), - custody_bit: false, - }; - &attestation_data_and_custody_bit.hash_tree_root() - }; // Signature verification. ensure!( bls_verify_aggregate( &group_public_key, - &attestation_message[..], + &attestation.signable_message(), &attestation.aggregate_signature, get_domain(&state.fork_data, attestation.data.slot, DOMAIN_ATTESTATION) ), diff --git a/eth2/types/src/attestation.rs b/eth2/types/src/attestation/mod.rs similarity index 99% rename from eth2/types/src/attestation.rs rename to eth2/types/src/attestation/mod.rs index d6738bd6ee..3b278ef8ce 100644 --- a/eth2/types/src/attestation.rs +++ b/eth2/types/src/attestation/mod.rs @@ -5,6 +5,8 @@ use rand::RngCore; use serde_derive::Serialize; use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash}; +mod signing; + #[derive(Debug, Clone, PartialEq, Serialize)] pub struct Attestation { pub data: AttestationData, diff --git a/eth2/types/src/attestation/signing.rs b/eth2/types/src/attestation/signing.rs new file mode 100644 index 0000000000..a2ef13d2f8 --- /dev/null +++ b/eth2/types/src/attestation/signing.rs @@ -0,0 +1,12 @@ +use crate::{Attestation, AttestationDataAndCustodyBit}; +use ssz::TreeHash; + +impl Attestation { + pub fn signable_message(&self) -> Vec { + let attestation_data_and_custody_bit = AttestationDataAndCustodyBit { + data: self.data.clone(), + custody_bit: false, + }; + attestation_data_and_custody_bit.hash_tree_root() + } +}