Add signable_message()
to AttestationData
This commit is contained in:
parent
4f1aeb2c79
commit
a037fec283
@ -1,4 +1,4 @@
|
||||
use super::{AttestationData, Bitfield};
|
||||
use super::{AttestationData, Bitfield, Hash256};
|
||||
use crate::test_utils::TestRandom;
|
||||
use bls::AggregateSignature;
|
||||
use rand::RngCore;
|
||||
@ -15,6 +15,12 @@ pub struct Attestation {
|
||||
pub aggregate_signature: AggregateSignature,
|
||||
}
|
||||
|
||||
impl Attestation {
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from(&self.hash_tree_root()[..])
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Attestation {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.data);
|
||||
|
@ -1,12 +1,7 @@
|
||||
use crate::{Attestation, AttestationDataAndCustodyBit};
|
||||
use ssz::TreeHash;
|
||||
use crate::Attestation;
|
||||
|
||||
impl Attestation {
|
||||
pub fn signable_message(&self) -> Vec<u8> {
|
||||
let attestation_data_and_custody_bit = AttestationDataAndCustodyBit {
|
||||
data: self.data.clone(),
|
||||
custody_bit: false,
|
||||
};
|
||||
attestation_data_and_custody_bit.hash_tree_root()
|
||||
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {
|
||||
self.data.signable_message(custody_bit)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ use rand::RngCore;
|
||||
use serde_derive::Serialize;
|
||||
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
|
||||
|
||||
mod signing;
|
||||
|
||||
pub const SSZ_ATTESTION_DATA_LENGTH: usize = {
|
||||
8 + // slot
|
||||
8 + // shard
|
12
eth2/types/src/attestation_data/signing.rs
Normal file
12
eth2/types/src/attestation_data/signing.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::{AttestationData, AttestationDataAndCustodyBit};
|
||||
use ssz::TreeHash;
|
||||
|
||||
impl AttestationData {
|
||||
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {
|
||||
let attestation_data_and_custody_bit = AttestationDataAndCustodyBit {
|
||||
data: self.clone(),
|
||||
custody_bit,
|
||||
};
|
||||
attestation_data_and_custody_bit.hash_tree_root()
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ macro_rules! ensure {
|
||||
};
|
||||
}
|
||||
|
||||
const PHASE_0_CUSTODY_BIT: bool = false;
|
||||
|
||||
// TODO: define elsehwere.
|
||||
const DOMAIN_ATTESTATION: u64 = 1;
|
||||
|
||||
@ -76,7 +78,7 @@ impl BeaconState {
|
||||
ensure!(
|
||||
bls_verify_aggregate(
|
||||
&group_public_key,
|
||||
&attestation.signable_message(),
|
||||
&attestation.signable_message(PHASE_0_CUSTODY_BIT),
|
||||
&attestation.aggregate_signature,
|
||||
get_domain(&self.fork_data, attestation.data.slot, DOMAIN_ATTESTATION)
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user