0.1.0-pre.004

This commit is contained in:
2026-07-23 18:25:10 +02:00
parent 0da75c1311
commit 149d4c6ef6
85 changed files with 25696 additions and 227 deletions

View File

@@ -1,22 +1,190 @@
// file: kb-program-ids/src/lib.rs
// version: 1
// version: 2
#![forbid(unsafe_code)]
#![deny(unreachable_pub)]
#![warn(missing_docs)]
//! Program identifier registry.
//! Shared canonical Solana program identifiers.
/// One program identifier entry.
#[derive(Clone, Debug, Eq, PartialEq)]
mod constants;
/// Address Lookup Table program identifier.
pub use constants::ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
/// Deprecated BPF Loader program identifier.
pub use constants::BPF_LOADER_DEPRECATED_PROGRAM_ID;
/// BPF Loader version 2 program identifier.
pub use constants::BPF_LOADER_PROGRAM_ID;
/// Upgradeable BPF Loader program identifier.
pub use constants::BPF_LOADER_UPGRADEABLE_PROGRAM_ID;
/// Compute Budget program identifier.
pub use constants::COMPUTE_BUDGET_PROGRAM_ID;
/// Config program identifier.
pub use constants::CONFIG_PROGRAM_ID;
/// Ed25519 precompile program identifier.
pub use constants::ED25519_PROGRAM_ID;
/// Feature program identifier.
pub use constants::FEATURE_PROGRAM_ID;
/// Incinerator well-known account identifier.
pub use constants::INCINERATOR_PROGRAM_ID;
/// Loader version 4 program identifier.
pub use constants::LOADER_V4_PROGRAM_ID;
/// Native Loader program identifier.
pub use constants::NATIVE_LOADER_PROGRAM_ID;
/// Internal list of executable native programs.
pub(crate) use constants::NATIVE_PROGRAM_ID_ENTRIES;
/// Internal list of native well-known accounts.
pub(crate) use constants::NATIVE_WELL_KNOWN_ACCOUNT_ID_ENTRIES;
/// Internal list of currently registered identifiers.
pub(crate) use constants::PROGRAM_ID_ENTRIES;
/// Secp256k1 precompile program identifier.
pub use constants::SECP256K1_PROGRAM_ID;
/// Secp256r1 precompile program identifier.
pub use constants::SECP256R1_PROGRAM_ID;
/// Enshrined stateless Slashing program identifier.
pub use constants::SLASHING_PROGRAM_ID;
/// Classic SPL Token program identifier.
pub use constants::SPL_TOKEN_PROGRAM_ID;
/// Historical Stake configuration account identifier.
pub use constants::STAKE_CONFIG_ACCOUNT_ID;
/// Compatibility alias for the historical Stake configuration account identifier.
pub use constants::STAKE_CONFIG_PROGRAM_ID;
/// Stake program identifier.
pub use constants::STAKE_PROGRAM_ID;
/// System program identifier.
pub use constants::SYSTEM_PROGRAM_ID;
/// Clock sysvar account identifier.
pub use constants::SYSVAR_CLOCK_PROGRAM_ID;
/// Instructions sysvar account identifier.
pub use constants::SYSVAR_INSTRUCTIONS_PROGRAM_ID;
/// Rent sysvar account identifier.
pub use constants::SYSVAR_RENT_PROGRAM_ID;
/// Slot Hashes sysvar account identifier.
pub use constants::SYSVAR_SLOT_HASHES_PROGRAM_ID;
/// Stake History sysvar account identifier.
pub use constants::SYSVAR_STAKE_HISTORY_PROGRAM_ID;
/// Vote program identifier.
pub use constants::VOTE_PROGRAM_ID;
/// ZK ElGamal Proof program identifier.
pub use constants::ZK_ELGAMAL_PROOF_PROGRAM_ID;
/// ZK Token Proof program identifier.
pub use constants::ZK_TOKEN_PROOF_PROGRAM_ID;
/// One enumerable program identifier entry.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ProgramIdEntry {
/// Stable symbolic name.
/// Stable lower snake case registry code.
pub name: &'static str,
/// Base58 program identifier.
/// Base58 Solana program identifier.
pub address: &'static str,
}
/// Returns the initial canonical program registry.
pub fn entries() -> &'static [crate::ProgramIdEntry] {
return &[];
impl ProgramIdEntry {
/// Returns the stable lower snake case registry code.
pub const fn code(&self) -> &'static str {
return self.name;
}
/// Returns the Base58 Solana program identifier.
pub const fn program_id(&self) -> &'static str {
return self.address;
}
}
/// Returns every program identifier currently registered by this crate.
pub fn entries() -> &'static [crate::ProgramIdEntry] {
return crate::PROGRAM_ID_ENTRIES;
}
/// Returns every program identifier currently registered by this crate.
pub fn registered_program_ids() -> &'static [crate::ProgramIdEntry] {
return crate::PROGRAM_ID_ENTRIES;
}
/// Returns every executable runtime-native, loader, precompile and historical native program identifier.
pub fn native_program_ids() -> &'static [crate::ProgramIdEntry] {
return crate::NATIVE_PROGRAM_ID_ENTRIES;
}
/// Returns native well-known accounts that are not executable programs.
pub fn native_well_known_account_ids() -> &'static [crate::ProgramIdEntry] {
return crate::NATIVE_WELL_KNOWN_ACCOUNT_ID_ENTRIES;
}
/// Finds one registered program or well-known account by exact Base58 identifier.
pub fn find_registered_program_id(
program_id: &str,
) -> std::option::Option<&'static crate::ProgramIdEntry> {
return crate::PROGRAM_ID_ENTRIES
.iter()
.find(|entry| return entry.address == program_id);
}
#[cfg(test)]
mod tests {
#[test]
fn registry_entries_are_unique_and_non_empty() {
let mut codes = std::collections::BTreeSet::new();
let mut program_ids = std::collections::BTreeSet::new();
for entry in crate::registered_program_ids() {
assert!(!entry.code().is_empty());
assert!(!entry.program_id().is_empty());
assert!(codes.insert(entry.code()));
assert!(program_ids.insert(entry.program_id()));
}
assert_eq!(crate::registered_program_ids().len(), 26);
}
#[test]
fn native_registry_contains_exactly_every_solana_core_surface() {
let codes = crate::native_program_ids()
.iter()
.map(crate::ProgramIdEntry::code)
.collect::<std::collections::BTreeSet<_>>();
assert!(codes.contains("vote"));
assert!(codes.contains("slashing"));
assert!(codes.contains("bpf_loader_deprecated"));
assert!(codes.contains("bpf_loader"));
assert!(codes.contains("bpf_loader_upgradeable"));
assert!(codes.contains("loader_v4"));
assert_eq!(codes.len(), 18);
assert_eq!(codes.len(), crate::native_program_ids().len());
}
#[test]
fn stake_config_is_a_well_known_account_not_an_executable_program() {
assert!(crate::native_well_known_account_ids().iter().any(|entry| {
return entry.program_id() == crate::STAKE_CONFIG_ACCOUNT_ID;
}));
assert!(!crate::native_program_ids().iter().any(|entry| {
return entry.program_id() == crate::STAKE_CONFIG_ACCOUNT_ID;
}));
}
#[test]
fn registry_lookup_finds_system_program() {
let entry = crate::find_registered_program_id(crate::SYSTEM_PROGRAM_ID);
assert_eq!(entry.map(crate::ProgramIdEntry::code), std::option::Option::Some("system"));
}
#[test]
fn compatibility_api_and_core_constants_are_complete() {
assert_eq!(crate::entries(), crate::registered_program_ids());
assert_eq!(crate::STAKE_CONFIG_PROGRAM_ID, crate::STAKE_CONFIG_ACCOUNT_ID);
let expected = [
crate::ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
crate::COMPUTE_BUDGET_PROGRAM_ID,
crate::CONFIG_PROGRAM_ID,
crate::FEATURE_PROGRAM_ID,
crate::SYSTEM_PROGRAM_ID,
crate::VOTE_PROGRAM_ID,
crate::STAKE_PROGRAM_ID,
crate::SLASHING_PROGRAM_ID,
crate::ZK_ELGAMAL_PROOF_PROGRAM_ID,
crate::ZK_TOKEN_PROOF_PROGRAM_ID,
];
for program_id in expected {
assert!(crate::find_registered_program_id(program_id).is_some());
}
}
}