Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,16 @@ pub fn stateful_checks(
let Ok(aggregator) = state.validator(aggregator_index) else {
return Err(Outcome::Reject(RejectReason::UnknownValidator));
};
let aggregator_pubkey = bls::IndexedPubkey {
index: aggregator_index,
pubkey: aggregator.pubkey,
};
// [REJECT] The selection proof selects the validator as an aggregator.
let selection_proof = aggregate.selection_proof();
let selection_domain =
get_domain_from_schedule(&config, &state, DOMAIN_SELECTION_PROOF, target_epoch);
let selection_signing_root = compute_signing_root(data.slot.hash_tree_root(), selection_domain);
if !bls::verify(&aggregator.pubkey, selection_signing_root, &selection_proof) {
if !bls::verify(&aggregator_pubkey, selection_signing_root, &selection_proof) {
return Err(Outcome::Reject(RejectReason::SelectionProof));
}
// [REJECT] The aggregator's own signature, over the whole envelope.
Expand All @@ -401,7 +405,7 @@ pub fn stateful_checks(
let aggregator_signing_root =
compute_signing_root(aggregate_and_proof_root(aggregate), aggregator_domain);
if !bls::verify(
&aggregator.pubkey,
&aggregator_pubkey,
aggregator_signing_root,
&aggregate.signature(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ pub fn stateful_checks(store: &Store, attestation: &SingleAttestation, subnet_id
};
let domain = get_domain_from_schedule(&config, &state, DOMAIN_BEACON_ATTESTER, target_epoch);
let signing_root = compute_signing_root(data.hash_tree_root(), domain);
if !bls::verify(&attester.pubkey, signing_root, &attestation.signature) {
let attester = bls::IndexedPubkey {
index: attestation.attester_index,
pubkey: attester.pubkey,
};
if !bls::verify(&attester, signing_root, &attestation.signature) {
return Outcome::Reject(RejectReason::BadSignature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,12 @@ fn header_signature_is_valid(
state.genesis_validators_root(),
);
let signing_root = compute_signing_root(header.hash_tree_root(), domain);
let proposer = bls::IndexedPubkey {
index: header.proposer_index,
pubkey: proposer.pubkey,
};
if !bls::verify(
&proposer.pubkey,
&proposer,
signing_root,
&sidecar.signed_block_header.signature,
) {
Expand Down
12 changes: 10 additions & 2 deletions crates/blockchain/state_transition/src/beacon/gossip/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ fn voluntary_exit(state: &BeaconState, signed: &SignedVoluntaryExit, config: &Co
state.genesis_validators_root(),
);
let signing_root = compute_signing_root(exit.hash_tree_root(), domain);
if !bls::verify(&validator.pubkey, signing_root, &signed.signature) {
let validator = bls::IndexedPubkey {
index: exit.validator_index,
pubkey: validator.pubkey,
};
if !bls::verify(&validator, signing_root, &signed.signature) {
return Err(Outcome::Reject(RejectReason::BadSignature));
}
Ok(())
Expand All @@ -264,6 +268,10 @@ fn proposer_slashing(state: &BeaconState, slashing: &ProposerSlashing) -> Verdic
if !is_slashable_validator(proposer, get_current_epoch(state)) {
return Err(Outcome::Reject(RejectReason::InvalidOperation));
}
let proposer = bls::IndexedPubkey {
index: proposer_index,
pubkey: proposer.pubkey,
};
// [REJECT] Both signatures are valid.
for signed_header in [&slashing.signed_header_1, &slashing.signed_header_2] {
let header = &signed_header.message;
Expand All @@ -273,7 +281,7 @@ fn proposer_slashing(state: &BeaconState, slashing: &ProposerSlashing) -> Verdic
Some(compute_epoch_at_slot(header.slot)),
);
let signing_root = compute_signing_root(header.hash_tree_root(), domain);
if !bls::verify(&proposer.pubkey, signing_root, &signed_header.signature) {
if !bls::verify(&proposer, signing_root, &signed_header.signature) {
return Err(Outcome::Reject(RejectReason::BadSignature));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ pub fn stateful_checks(store: &Store, message: &gloas::PayloadAttestationMessage
Some(compute_epoch_at_slot(data.slot)),
);
let signing_root = compute_signing_root(data.hash_tree_root(), domain);
if !bls::verify(&validator.pubkey, signing_root, &message.signature) {
let validator = bls::IndexedPubkey {
index: validator_index,
pubkey: validator.pubkey,
};
if !bls::verify(&validator, signing_root, &message.signature) {
return Outcome::Reject(RejectReason::BadSignature);
}
Outcome::Accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ fn stateful_rules(store: &Store, signed: &gloas::SignedProposerPreferences) -> R
return Err(Outcome::Reject(RejectReason::WrongProposer));
}
// [REJECT] The signature is valid, under any candidate domain.
let pubkey = state
.validator(preferences.validator_index)
.map_err(|_| Outcome::Reject(RejectReason::WrongProposer))?
.pubkey;
let pubkey = bls::IndexedPubkey {
index: preferences.validator_index,
pubkey: state
.validator(preferences.validator_index)
.map_err(|_| Outcome::Reject(RejectReason::WrongProposer))?
.pubkey,
};
let message_root = preferences.hash_tree_root();
let valid = proposer_preferences_domains(&state, &config, proposal_epoch)
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ pub fn check_message(
message.slot,
message.beacon_block_root,
);
if !bls::verify(&validator.pubkey, signing_root, &message.signature) {
let validator = bls::IndexedPubkey {
index: message.validator_index,
pubkey: validator.pubkey,
};
if !bls::verify(&validator, signing_root, &message.signature) {
return Err(Outcome::Reject(RejectReason::BadSignature));
}
Ok(seats)
Expand Down Expand Up @@ -353,12 +357,16 @@ pub fn check_contribution(
contribution.slot,
contribution.subcommittee_index,
);
if !bls::verify(&aggregator.pubkey, selection_root, &message.selection_proof) {
let aggregator_pubkey = bls::IndexedPubkey {
index: message.aggregator_index,
pubkey: aggregator.pubkey,
};
if !bls::verify(&aggregator_pubkey, selection_root, &message.selection_proof) {
return Outcome::Reject(RejectReason::SelectionProof);
}
// [REJECT] The aggregator's signature over the envelope is valid.
let envelope_root = contribution_and_proof_signing_root(config, gvr, message);
if !bls::verify(&aggregator.pubkey, envelope_root, &signed.signature) {
if !bls::verify(&aggregator_pubkey, envelope_root, &signed.signature) {
return Outcome::Reject(RejectReason::AggregatorSignature);
}
// [REJECT] The aggregate signature is valid over the participants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use ethlambda_storage::{
ActiveBalanceCache, ActiveBalanceKey, CommitteeCache, Lookup, ShufflingKey,
};

use crate::beacon::bls::{AggregatePubkey, CommitteeKeySums};
use crate::beacon::bls::{AggregatePubkey, CommitteeKeySums, IndexedPubkey};
use crate::beacon::config::Config;
use crate::beacon::constants;
use crate::beacon::containers::BeaconState;
Expand Down Expand Up @@ -416,9 +416,14 @@ fn build_committee_key_sums(
let sums = members
.par_iter()
.map(|committee| {
let keys: Option<Vec<BlsPubkey>> = committee
// The index is attached per committee rather than stored in the
// flat list, which spans the whole registry.
let keys: Option<Vec<IndexedPubkey>> = committee
.iter()
.map(|index| pubkeys.get(*index as usize).copied())
.map(|&index| {
let pubkey = *pubkeys.get(index as usize)?;
Some(IndexedPubkey { index, pubkey })
})
.collect();
AggregatePubkey::sum(&keys?)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! the aggregation bits from one committee to a whole slot's worth and adding a
//! committee bitfield, so it gets its own versions rather than reusing these.

use crate::beacon::bls::SignatureSet;
use crate::beacon::bls::{IndexedPubkey, SignatureSet};
use crate::beacon::constants;
use crate::beacon::containers::BeaconState;
use crate::beacon::containers::phase0::{Attestation, AttestingIndices, IndexedAttestation};
Expand Down Expand Up @@ -132,7 +132,10 @@ pub fn indexed_attestation_signature_set_with_domain(
let mut pubkeys = Vec::with_capacity(indices.len());
for index in indices {
match state.validator(*index) {
Ok(validator) => pubkeys.push(validator.pubkey),
Ok(validator) => pubkeys.push(IndexedPubkey {
index: *index,
pubkey: validator.pubkey,
}),
Err(_) => return None,
}
}
Expand Down
14 changes: 11 additions & 3 deletions crates/blockchain/state_transition/src/beacon/helpers/electra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
//! single easiest mistake to make copying that shape without also copying
//! the reasoning behind it.

use crate::beacon::bls::{AggregatePubkey, SignatureSet};
use crate::beacon::bls::{AggregatePubkey, IndexedPubkey, SignatureSet};
use crate::beacon::config::Config;
use crate::beacon::constants::{self, FAR_FUTURE_EPOCH};
use crate::beacon::containers::shared::{AttestationData, Validator};
Expand Down Expand Up @@ -331,7 +331,10 @@ pub fn indexed_attestation_signature_set_with_domain(
let mut pubkeys = Vec::with_capacity(indices.len());
for index in indices {
match state.validator(*index) {
Ok(validator) => pubkeys.push(validator.pubkey),
Ok(validator) => pubkeys.push(IndexedPubkey {
index: *index,
pubkey: validator.pubkey,
}),
Err(_) => return None,
}
}
Expand Down Expand Up @@ -577,7 +580,12 @@ pub(crate) fn attesters_aggregate_pubkey(
let key_sums = committees.key_sums(state, epoch);
let committees_per_slot = epoch_committees.committees_per_slot();

let pubkey_of = |index: ValidatorIndex| state.validator(index).ok().map(|v| v.pubkey);
let pubkey_of = |index: ValidatorIndex| {
state.validator(index).ok().map(|v| IndexedPubkey {
index,
pubkey: v.pubkey,
})
};

// Committees derived from their sums, added as they come, and the keys of
// every committee summed directly, summed once at the end.
Expand Down
12 changes: 9 additions & 3 deletions crates/blockchain/state_transition/src/beacon/helpers/gloas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
//! doc), read through [`super::fulu::get_beacon_proposer_index`] rather
//! than a copy of it here.

use crate::beacon::bls::SignatureSet;
use crate::beacon::bls::{IndexedPubkey, SignatureSet};
use crate::beacon::config::Config;
use crate::beacon::constants;
use crate::beacon::containers::shared::AttestationData;
Expand Down Expand Up @@ -178,7 +178,10 @@ pub fn indexed_attestation_signature_set_with_domain(
let mut pubkeys = Vec::with_capacity(indices.len());
for index in indices {
match state.validator(*index) {
Ok(validator) => pubkeys.push(validator.pubkey),
Ok(validator) => pubkeys.push(IndexedPubkey {
index: *index,
pubkey: validator.pubkey,
}),
Err(_) => return None,
}
}
Expand Down Expand Up @@ -353,7 +356,10 @@ pub fn indexed_payload_attestation_signature_set(
let mut pubkeys = Vec::with_capacity(indices.len());
for index in indices {
match state.validator(*index) {
Ok(validator) => pubkeys.push(validator.pubkey),
Ok(validator) => pubkeys.push(IndexedPubkey {
index: *index,
pubkey: validator.pubkey,
}),
Err(_) => return None,
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/blockchain/state_transition/src/beacon/precheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ pub fn precheck_block(
};

let pubkey = match (state.validator(proposer), reference) {
(Ok(validator), _) => &validator.pubkey,
(Ok(validator), _) => bls::IndexedPubkey {
index: proposer,
pubkey: validator.pubkey,
},
(Err(_), Reference::Parent(_)) => {
return Err(PrecheckError::UnknownProposer { proposer });
}
Expand All @@ -125,7 +128,7 @@ pub fn precheck_block(
state.genesis_validators_root(),
);
let signing_root = compute_signing_root(block_root, domain);
if !bls::verify(pubkey, signing_root, &signed_block.signature()) {
if !bls::verify(&pubkey, signing_root, &signed_block.signature()) {
return Err(PrecheckError::BadSignature);
}
Ok(())
Expand Down
11 changes: 9 additions & 2 deletions crates/blockchain/state_transition/src/beacon/stf/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! every driver, present and future, call the identical function regardless of
//! what else that fork's body carries.

use crate::beacon::bls::SignatureSet;
use crate::beacon::bls::{IndexedPubkey, SignatureSet};
use crate::beacon::config::Config;
use crate::beacon::constants;
use crate::beacon::containers::{self, BeaconBlockHeader, BeaconState, Eth1Data, altair, phase0};
Expand Down Expand Up @@ -352,7 +352,14 @@ pub fn process_randao(
let proposer = state.validator(proposer_index)?;
if verification == RandaoVerification::Verify {
signatures.push(
SignatureSet::single(&proposer.pubkey, signing_root, randao_reveal),
SignatureSet::single(
&IndexedPubkey {
index: proposer_index,
pubkey: proposer.pubkey,
},
signing_root,
randao_reveal,
),
"RANDAO reveal signature",
)?;
}
Expand Down
7 changes: 5 additions & 2 deletions crates/blockchain/state_transition/src/beacon/stf/deneb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! caches two new blob-gas fields for EIP-4844, and [`process_voluntary_exit`]
//! signs under a fixed fork version for EIP-7044.

use crate::beacon::bls::SignatureSet;
use crate::beacon::bls::{IndexedPubkey, SignatureSet};
use crate::beacon::config::Config;
use crate::beacon::constants::{self, FAR_FUTURE_EPOCH};
use crate::beacon::containers::capella::SignedBLSToExecutionChange;
Expand Down Expand Up @@ -712,7 +712,10 @@ pub fn process_voluntary_exit(
let signing_root = compute_signing_root(voluntary_exit.hash_tree_root(), domain);
signatures.push(
SignatureSet::single(
&validator.pubkey,
&IndexedPubkey {
index: voluntary_exit.validator_index,
pubkey: validator.pubkey,
},
signing_root,
&signed_voluntary_exit.signature,
),
Expand Down
7 changes: 5 additions & 2 deletions crates/blockchain/state_transition/src/beacon/stf/electra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

use libssz::SszEncode as _;

use crate::beacon::bls::{self, SignatureSet};
use crate::beacon::bls::{self, IndexedPubkey, SignatureSet};
use crate::beacon::config::Config;
use crate::beacon::constants::{self, FAR_FUTURE_EPOCH};
use crate::beacon::containers::shared::{
Expand Down Expand Up @@ -532,7 +532,10 @@ pub fn process_voluntary_exit(
let signing_root = compute_signing_root(voluntary_exit.hash_tree_root(), domain);
signatures.push(
SignatureSet::single(
&validator.pubkey,
&IndexedPubkey {
index: voluntary_exit.validator_index,
pubkey: validator.pubkey,
},
signing_root,
&signed_voluntary_exit.signature,
),
Expand Down
9 changes: 7 additions & 2 deletions crates/blockchain/state_transition/src/beacon/stf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,15 @@ pub fn block_signature_set(
state: &BeaconState,
signed_block: &containers::SignedBeaconBlock,
) -> Option<bls::SignatureSet> {
let proposer = state.validator(signed_block.proposer_index()).ok()?;
let index = signed_block.proposer_index();
let proposer = state.validator(index).ok()?;
let domain = get_domain(state, constants::DOMAIN_BEACON_PROPOSER, None);
let signing_root = compute_signing_root(signed_block.message_hash_tree_root(), domain);
bls::SignatureSet::single(&proposer.pubkey, signing_root, &signed_block.signature())
let proposer = bls::IndexedPubkey {
index,
pubkey: proposer.pubkey,
};
bls::SignatureSet::single(&proposer, signing_root, &signed_block.signature())
}

/// Advances the state to `slot`, running epoch processing at each boundary and
Expand Down
Loading
Loading