Add more gossip verification conditions

This commit is contained in:
Pawan Dhananjay
2022-10-06 21:16:57 -05:00
parent 44515b8cbe
commit 1430b561c3
2 changed files with 100 additions and 34 deletions

View File

@@ -1,7 +1,9 @@
use crate::{BlobsSidecar, EthSpec};
use crate::{
signing_data::SignedRoot, BlobsSidecar, ChainSpec, Domain, EthSpec, Fork, Hash256, PublicKey,
SigningData,
};
use bls::Signature;
use serde_derive::{Deserialize, Serialize};
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use tree_hash::TreeHash;
use tree_hash_derive::TreeHash;
@@ -21,4 +23,36 @@ impl<T: EthSpec> SignedBlobsSidecar<T> {
signature,
}
}
/// Verify `self.signature`.
///
/// If the root of `blob_sidecar.message` is already known it can be passed in via `object_root_opt`.
/// Otherwise, it will be computed locally.
pub fn verify_signature(
&self,
object_root_opt: Option<Hash256>,
pubkey: &PublicKey,
fork: &Fork,
genesis_validators_root: Hash256,
spec: &ChainSpec,
) -> bool {
let domain = spec.get_domain(
self.message.beacon_block_slot.epoch(T::slots_per_epoch()),
Domain::BlobsSideCar,
fork,
genesis_validators_root,
);
let message = if let Some(object_root) = object_root_opt {
SigningData {
object_root,
domain,
}
.tree_hash_root()
} else {
self.message.signing_root(domain)
};
self.signature.verify(pubkey, message)
}
}