Skip to content

Commit fb1582b

Browse files
authored
Introduces Bank::verify_certificate (#10682)
introduce `Bank::verify_certificate`
1 parent 6b2edb9 commit fb1582b

File tree

7 files changed

+63
-2
lines changed

7 files changed

+63
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bls-cert-verify/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ wincode = { workspace = true }
2828
[dev-dependencies]
2929
# See order-crates-for-publishing.py for using this unusual `path = "."`
3030
agave-bls-cert-verify = { path = ".", features = ["agave-unstable-api", "dev-context-only-utils"] }
31-
agave-votor = { workspace = true }
31+
# See order-crates-for-publishing.py for using this unusual `path`
32+
agave-votor = { path = "../votor" }
3233
criterion = { workspace = true }
3334
solana-hash = { workspace = true }
3435

dev-bins/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

programs/sbf/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ frozen-abi = [
5151
shuttle-test = ["dep:shuttle"]
5252

5353
[dependencies]
54+
agave-bls-cert-verify = { workspace = true }
5455
agave-feature-set = { workspace = true }
5556
agave-fs = { workspace = true }
5657
agave-precompiles = { workspace = true }

runtime/src/bank.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use {
6363
transaction_batch::{OwnedOrBorrowed, TransactionBatch},
6464
},
6565
accounts_lt_hash::{CacheValue as AccountsLtHashCacheValue, Stats as AccountsLtHashStats},
66+
agave_bls_cert_verify::cert_verify::{self, Error as CertVerifyError},
6667
agave_feature_set::{
6768
self as feature_set, increase_cpi_account_info_limit, raise_cpi_nesting_limit_to_8,
6869
relax_programdata_account_check_migration, FeatureSet,
@@ -5163,6 +5164,29 @@ impl Bank {
51635164
self.epoch_stakes.get(&epoch)
51645165
}
51655166

5167+
/// Verify a BLS certificate's signature using this bank's epoch stakes.
5168+
///
5169+
/// Returns (stake present in certificate, total stake in validator set) on success.
5170+
pub fn verify_certificate(
5171+
&self,
5172+
cert: &Certificate,
5173+
) -> std::result::Result<(u64, u64), CertVerifyError> {
5174+
let slot = cert.cert_type.slot();
5175+
let epoch_stakes = self
5176+
.epoch_stakes_from_slot(slot)
5177+
.ok_or(CertVerifyError::MissingRankMap)?;
5178+
let key_to_rank_map = epoch_stakes.bls_pubkey_to_rank_map();
5179+
let total_stake = epoch_stakes.total_stake();
5180+
5181+
let stake = cert_verify::verify_certificate(cert, key_to_rank_map.len(), |rank| {
5182+
key_to_rank_map
5183+
.get_pubkey_stake_entry(rank)
5184+
.map(|entry| (entry.stake, entry.bls_pubkey))
5185+
})?;
5186+
5187+
Ok((stake, total_stake))
5188+
}
5189+
51665190
pub fn epoch_stakes_map(&self) -> &HashMap<Epoch, VersionedEpochStakes> {
51675191
&self.epoch_stakes
51685192
}

runtime/src/epoch_stakes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct BLSPubkeyStakeEntry {
3636
pub struct BLSPubkeyToRankMap {
3737
/// Mapping from validator [`BLSPubkey`] to rank.
3838
rank_map: HashMap<BLSPubkey, u16>,
39-
/// Mapping from rank to validator [`(Pubkey, BLSPubkey)`].
39+
/// Mapping from rank to [`BLSPubkeyStakeEntry`].
4040
//
4141
// TODO(wen): We can make sorted_pubkeys a Vec<BLSPubkey> after we remove ed25519
4242
// pubkey from the consensus pool.

0 commit comments

Comments
 (0)