v0.1.0-pre.008

This commit is contained in:
2026-07-23 20:40:38 +02:00
parent f5bd8fab7f
commit 12b42a31b8
26 changed files with 6686 additions and 280 deletions

View File

@@ -1,5 +1,5 @@
// file: kb-program-ids/src/constants.rs
// version: 3
// version: 4
//! Canonical Solana program and well-known account identifiers.
@@ -43,6 +43,9 @@ pub const SPL_MEMO_V4_PROGRAM_ID: &str = "Memo4c2pN8afCj432Lb7RMVKi9PbQnnW7ewFFa
pub const SPL_TOKEN_PROGRAM_ID: &str = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
/// SPL Token-2022 program identifier.
pub const SPL_TOKEN_2022_PROGRAM_ID: &str = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
/// SPL Token-2022 ElGamal public-key registry program identifier.
pub const SPL_TOKEN_2022_ELGAMAL_REGISTRY_PROGRAM_ID: &str =
"regVYJW7tcT8zipN5YiBvHsvR5jXW1uLFxaHSbugABg";
/// Historical Stake configuration account identifier.
pub const STAKE_CONFIG_ACCOUNT_ID: &str = "StakeConfig11111111111111111111111111111111";
/// Compatibility alias for the historical Stake configuration account identifier.
@@ -235,6 +238,10 @@ pub(crate) const PROGRAM_ID_ENTRIES: &[crate::ProgramIdEntry] = &[
name: "spl_token_2022",
address: crate::SPL_TOKEN_2022_PROGRAM_ID,
},
crate::ProgramIdEntry {
name: "spl_token_2022_elgamal_registry",
address: crate::SPL_TOKEN_2022_ELGAMAL_REGISTRY_PROGRAM_ID,
},
crate::ProgramIdEntry {
name: "stake_config",
address: crate::STAKE_CONFIG_ACCOUNT_ID,

View File

@@ -1,5 +1,5 @@
// file: kb-program-ids/src/lib.rs
// version: 5
// version: 7
#![forbid(unsafe_code)]
#![deny(unreachable_pub)]
@@ -8,6 +8,14 @@
//! Shared canonical Solana program identifiers.
mod constants;
mod programs;
/// 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;
/// Address Lookup Table program identifier.
pub use constants::ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
@@ -33,12 +41,6 @@ pub use constants::INCINERATOR_PROGRAM_ID;
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.
@@ -51,6 +53,8 @@ pub use constants::SPL_MEMO_V1_PROGRAM_ID;
pub use constants::SPL_MEMO_V3_PROGRAM_ID;
/// Current SPL Memo v4 program identifier.
pub use constants::SPL_MEMO_V4_PROGRAM_ID;
/// SPL Token-2022 ElGamal public-key registry program identifier.
pub use constants::SPL_TOKEN_2022_ELGAMAL_REGISTRY_PROGRAM_ID;
/// SPL Token-2022 program identifier.
pub use constants::SPL_TOKEN_2022_PROGRAM_ID;
/// Classic SPL Token program identifier.
@@ -79,142 +83,15 @@ pub use constants::VOTE_PROGRAM_ID;
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 lower snake case registry code.
pub name: &'static str,
/// Base58 Solana program identifier.
pub address: &'static str,
}
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;
}
}
pub use programs::ProgramIdEntry;
/// 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;
}
pub use programs::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(), 31);
}
#[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());
}
}
#[test]
fn spl_primitives_are_registered_without_joining_native_surfaces() {
let spl_program_ids = [
crate::SPL_MEMO_V1_PROGRAM_ID,
crate::SPL_MEMO_V3_PROGRAM_ID,
crate::SPL_MEMO_V4_PROGRAM_ID,
crate::SPL_TOKEN_PROGRAM_ID,
crate::SPL_TOKEN_2022_PROGRAM_ID,
crate::ASSOCIATED_TOKEN_PROGRAM_ID,
];
for program_id in spl_program_ids {
assert!(crate::find_registered_program_id(program_id).is_some());
assert!(
!crate::native_program_ids()
.iter()
.any(|entry| return entry.program_id() == program_id)
);
}
}
}
pub use programs::find_registered_program_id;
/// Returns every executable runtime-native, loader, precompile and historical native program identifier.
pub use programs::native_program_ids;
/// Returns native well-known accounts that are not executable programs.
pub use programs::native_well_known_account_ids;
/// Returns every program identifier currently registered by this crate.
pub use programs::registered_program_ids;

View File

@@ -0,0 +1,144 @@
// file: kb-program-ids/src/programs.rs
// version: 1
//! Enumerable canonical program registry.
/// One enumerable program identifier entry.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ProgramIdEntry {
/// Stable lower snake case registry code.
pub name: &'static str,
/// Base58 Solana program identifier.
pub address: &'static str,
}
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(), 32);
}
#[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());
}
}
#[test]
fn spl_primitives_are_registered_without_joining_native_surfaces() {
let spl_program_ids = [
crate::SPL_MEMO_V1_PROGRAM_ID,
crate::SPL_MEMO_V3_PROGRAM_ID,
crate::SPL_MEMO_V4_PROGRAM_ID,
crate::SPL_TOKEN_PROGRAM_ID,
crate::SPL_TOKEN_2022_PROGRAM_ID,
crate::SPL_TOKEN_2022_ELGAMAL_REGISTRY_PROGRAM_ID,
crate::ASSOCIATED_TOKEN_PROGRAM_ID,
];
for program_id in spl_program_ids {
assert!(crate::find_registered_program_id(program_id).is_some());
assert!(
!crate::native_program_ids()
.iter()
.any(|entry| return entry.program_id() == program_id)
);
}
}
}