Skip to content

Commit

Permalink
Extract pubkey crate (#2394)
Browse files Browse the repository at this point in the history
* extract solana-pubkey from solana-program

* make curve25519_dalek an optional dep

* make sha2 optional in solana-pubkey

* move pubkey wasm code to solana-pubkey

* make serde optional in solana-pubkey

* make bytemuck optional in solana-pubkey

* put syscalls behind target_os = "solana"

* move rand to dev deps

* remove thiserror

* remove num_derive

* make std optional

* use std when target_arch = "wasm32"

* fix frozen-abi support

* update digests

* update digests

* update nits.sh

* update lock file

* make some doc examples text-only because order-crates-for-publishing.py is wrong

* add dev-context-only-utils to appease ci

* fmt

* fix unused import when target_os = "solana"

* fix imports in wasm target

* fix import issue

* activate std feat when borsh feat is activated

* fix a conditional import

* fix more feature issues

* add default-features = false (otherwise we can't disable default features anywhere in the workspace)

* activate std feature explicitly

* clean up imports

* fix test features

* fix lints

* post-rebase fixes

* make FromStr, Display and Debug no_std

* fmt

* update digest

* fix duplicate line post-rebase

* stop avoiding circular dev dep since CI now accommodates this

* make rustc_version optional

* fix doc link

* fix frozen-abi deps

* update digests

* fmt

* don't require std for FromStr

* simplify some imports

* use as_ref instead of to_bytes

Co-authored-by: Jon C <me@jonc.dev>

* use as_ref instead of to_bytes

Co-authored-by: Jon C <me@jonc.dev>

* remove unnecessary test criterion in #[cfg()]

Co-authored-by: Jon C <me@jonc.dev>

* remove unnecessary test criterion in #[cfg()]

Co-authored-by: Jon C <me@jonc.dev>

* remove unrelated change

* but don't remove #[cfg(test)]

* call out doc tests in explanation of circular dev dep

* add missing conversion

* remove unnecessary #[cfg(feature = "std")]

* use strum to check that FromPrimitive impls are exhaustive

* sort deps

* add test for From<u64>

---------

Co-authored-by: Jon C <me@jonc.dev>
  • Loading branch information
kevinheavey and joncinque committed Sep 10, 2024
1 parent 8116c10 commit 9e7637a
Show file tree
Hide file tree
Showing 27 changed files with 541 additions and 211 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ members = [
"sdk/program",
"sdk/program-memory",
"sdk/program-option",
"sdk/pubkey",
"sdk/serde-varint",
"sdk/sha256-hasher",
"sdk/signature",
Expand Down Expand Up @@ -423,6 +424,7 @@ solana-program-memory = { path = "sdk/program-memory", version = "=2.1.0" }
solana-program-option = { path = "sdk/program-option", version = "=2.1.0" }
solana-program-runtime = { path = "program-runtime", version = "=2.1.0" }
solana-program-test = { path = "program-test", version = "=2.1.0" }
solana-pubkey = { path = "sdk/pubkey", version = "=2.1.0", default-features = false }
solana-pubsub-client = { path = "pubsub-client", version = "=2.1.0" }
solana-quic-client = { path = "quic-client", version = "=2.1.0" }
solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.1.0" }
Expand Down
1 change: 1 addition & 0 deletions ci/nits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare print_free_tree=(
':^sdk/msg/src/lib.rs'
':^sdk/program-option/src/lib.rs'
':^sdk/program/src/program_stubs.rs'
':^sdk/pubkey/src/lib.rs'
':programs/**.rs'
':^**bin**.rs'
':^**bench**.rs'
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) enum BlockhashStatus {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "5BUswzvu7Qe44HbR4eBwPX4Jn9GSfhjmg8eijnBjoKUd")
frozen_abi(digest = "9ziHa1vA7WG5RCvXiE3g1f2qjSTNa47FB7e2czo7en7a")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower {
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "9P6J8ZtVLR5zbUxWT83q1iUsJMH6B7SwcomSqcoomPmg")
frozen_abi(digest = "6VhLW7DSHNzrcswtxbNo4cb47oGrKLcKuDmCWVpUMLLM")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_14_11 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower1_7_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "DJVvkk4EFFCbA37vsKcFPGuwEULh2wEvMUESsTyvABzU")
frozen_abi(digest = "5bwSGBqA1BVmgNtnTenfYtEt123cciEzpfqt6bUX1dJo")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_7_14 {
Expand Down
6 changes: 3 additions & 3 deletions core/src/repair/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl AncestorHashesRepairType {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "H7S44V9G9cjKeZdtSNZnRivsMrKaThkazF3k3c63TxP4")
frozen_abi(digest = "9SdneX58ekpqLJBzUwfwJsK2fZc9mN4vTcaS4temEjkP")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum AncestorHashesResponse {
Expand Down Expand Up @@ -224,7 +224,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "CYguF3KopGoM48XFJJS9pw9Z4TDZ2eUTqPPqbm3L4mFr")
frozen_abi(digest = "3E2R8jiSt9QfVHdX3MgW3UdeNWfor7zNjJcLJLz2K1JY")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum RepairProtocol {
Expand Down Expand Up @@ -272,7 +272,7 @@ fn discard_malformed_repair_requests(
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "8TYqNDnUGbE5duZgbCJAyZ2nZDSx39ueYo9PLLZCsiVy")
frozen_abi(digest = "CpKVYghdpMDRMiGjZpa71dcnB7rCVHLVogZbB3AGDKAK")
)]
#[derive(Debug, Deserialize, Serialize)]
pub(crate) enum RepairResponse {
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "ANgFTZHXSMbjYEuvf9YphECo47tWWrqKdPDD6B9D1YGB")
frozen_abi(digest = "GfVFxfPfYcFLCaa29uxQxyKJAuTZ1cYqcRKhVrEKwDK7")
)]
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down
24 changes: 24 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/src/bank/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ mod tests {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "FuFBQtx7rGruVC3cyh4zvZ3uN4RUtBiwh1pXJRwUCcoS")
frozen_abi(digest = "6d4H7gw1hSrspdTew8dAXZ5dZT1mwFc6VZdXnkuggJ8E")
)]
#[derive(Serialize)]
pub struct BankAbiTestWrapper {
Expand Down
5 changes: 4 additions & 1 deletion sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ solana-hash = { workspace = true, features = [
solana-msg = { workspace = true }
solana-program-memory = { workspace = true }
solana-program-option = { workspace = true }
solana-pubkey = { workspace = true, features = ["bytemuck", "curve25519", "serde", "std"] }
solana-sanitize = { workspace = true }
solana-sdk-macro = { workspace = true }
solana-secp256k1-recover = { workspace = true }
Expand Down Expand Up @@ -91,6 +92,7 @@ assert_matches = { workspace = true }
itertools = { workspace = true }
serde_json = { workspace = true }
serial_test = { workspace = true }
solana-pubkey = { workspace = true, features = ["dev-context-only-utils"] }
static_assertions = { workspace = true }
test-case = { workspace = true }

Expand All @@ -105,13 +107,14 @@ crate-type = ["cdylib", "rlib"]

[features]
default = ["borsh"]
borsh = ["dep:borsh", "dep:borsh0-10", "solana-hash/borsh"]
borsh = ["dep:borsh", "dep:borsh0-10", "solana-hash/borsh", "solana-pubkey/borsh"]
dev-context-only-utils = ["dep:qualifier_attr"]
frozen-abi = [
"dep:rustc_version",
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"solana-hash/frozen-abi",
"solana-pubkey/frozen-abi",
"solana-short-vec/frozen-abi"
]

Expand Down
6 changes: 4 additions & 2 deletions sdk/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ pub mod program_error;
pub mod program_pack;
pub mod program_stubs;
pub mod program_utils;
pub mod pubkey;
pub mod rent;
pub mod secp256k1_program;
pub mod serialize_utils;
Expand Down Expand Up @@ -539,7 +538,10 @@ pub use solana_serde_varint as serde_varint;
pub use solana_short_vec as short_vec;
#[cfg(target_arch = "wasm32")]
pub use wasm_bindgen::prelude::wasm_bindgen;
pub use {solana_clock as clock, solana_msg::msg, solana_program_option as program_option};
pub use {
solana_clock as clock, solana_msg::msg, solana_program_option as program_option,
solana_pubkey as pubkey,
};

/// The [config native program][np].
///
Expand Down
10 changes: 5 additions & 5 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ mod builtins {
// the value is "false"), or might be in one of these lists (if the value is "true")
pub static ref MAYBE_BUILTIN_KEY_OR_SYSVAR: [bool; 256] = {
let mut temp_table: [bool; 256] = [false; 256];
BUILTIN_PROGRAMS_KEYS.iter().for_each(|key| temp_table[key.0[0] as usize] = true);
sysvar::ALL_IDS.iter().for_each(|key| temp_table[key.0[0] as usize] = true);
BUILTIN_PROGRAMS_KEYS.iter().for_each(|key| temp_table[key.as_ref()[0] as usize] = true);
sysvar::ALL_IDS.iter().for_each(|key| temp_table[key.as_ref()[0] as usize] = true);
temp_table
};
}
Expand All @@ -76,7 +76,7 @@ mod builtins {
)]
#[allow(deprecated)]
pub fn is_builtin_key_or_sysvar(key: &Pubkey) -> bool {
if MAYBE_BUILTIN_KEY_OR_SYSVAR[key.0[0] as usize] {
if MAYBE_BUILTIN_KEY_OR_SYSVAR[key.as_ref()[0] as usize] {
return sysvar::is_sysvar_id(key) || BUILTIN_PROGRAMS_KEYS.contains(key);
}
false
Expand Down Expand Up @@ -123,7 +123,7 @@ fn compile_instructions(ixs: &[Instruction], keys: &[Pubkey]) -> Vec<CompiledIns
#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "8T1Vi17ZrAmakpGPcPo4cMR4stSpbGNP9teYoB6wVR4z"),
frozen_abi(digest = "4kL6EbLGU25m5eMk4H1cW9YGhA5LejHSgj2w2fhY1NGp"),
derive(AbiExample)
)]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -153,7 +153,7 @@ pub struct Message {
#[wasm_bindgen]
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "8T1Vi17ZrAmakpGPcPo4cMR4stSpbGNP9teYoB6wVR4z"),
frozen_abi(digest = "4kL6EbLGU25m5eMk4H1cW9YGhA5LejHSgj2w2fhY1NGp"),
derive(AbiExample)
)]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/message/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub const MESSAGE_VERSION_PREFIX: u8 = 0x80;
/// format.
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "3g49yJ9ZZPsT9iF6Za6FyWXV259vWcY6gfJ94uzQ5BcY"),
frozen_abi(digest = "EjjHMjAnRrd86DuTgysFXRicMiAQv3vTvzRzcMJCjYfC"),
derive(AbiEnumVisitor, AbiExample)
)]
#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down
7 changes: 4 additions & 3 deletions sdk/program/src/syscalls/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pub use solana_msg::sol_log;
note = "Use `solana_program_memory::syscalls` instead"
)]
pub use solana_program_memory::syscalls::{sol_memcmp_, sol_memcpy_, sol_memmove_, sol_memset_};
#[deprecated(since = "2.1.0", note = "Use `solana_pubkey::syscalls` instead")]
pub use solana_pubkey::syscalls::{
sol_create_program_address, sol_log_pubkey, sol_try_find_program_address,
};
#[deprecated(
since = "2.1.0",
note = "Use `solana_secp256k1_recover::sol_secp256k1_recover` instead"
Expand All @@ -23,9 +27,6 @@ use {
};
define_syscall!(fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64));
define_syscall!(fn sol_log_compute_units_());
define_syscall!(fn sol_log_pubkey(pubkey_addr: *const u8));
define_syscall!(fn sol_create_program_address(seeds_addr: *const u8, seeds_len: u64, program_id_addr: *const u8, address_bytes_addr: *const u8) -> u64);
define_syscall!(fn sol_try_find_program_address(seeds_addr: *const u8, seeds_len: u64, program_id_addr: *const u8, address_bytes_addr: *const u8, bump_seed_addr: *const u8) -> u64);
define_syscall!(fn sol_keccak256(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64);
define_syscall!(fn sol_blake3(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64);
define_syscall!(fn sol_invoke_signed_c(instruction_addr: *const u8, account_infos_addr: *const u8, account_infos_len: u64, signers_seeds_addr: *const u8, signers_seeds_len: u64) -> u64);
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/system_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static_assertions::const_assert_eq!(MAX_PERMITTED_DATA_LENGTH, 10_485_760);
/// An instruction to the system program.
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "5e22s2kFu9Do77hdcCyxyhuKHD8ThAB6Q6dNaLTCjL5M"),
frozen_abi(digest = "2LnVTnJg7LxB1FawNZLoQEY8yiYx3MT3paTdx4s5kAXU"),
derive(AbiExample, AbiEnumVisitor)
)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/vote/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl<I> CircBuf<I> {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "EeenjJaSrm9hRM39gK6raRNtzG61hnk7GciUCJJRDUSQ"),
frozen_abi(digest = "87ULMjjHnMsPmCTEyzj4KPn2u5gdX1rmgtSdycpbSaLs"),
derive(AbiExample)
)]
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/vote/state/vote_state_1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "CZTgLymuevXjAx6tM8X8T5J3MCx9AkEsFSmu4FJrEpkG"),
frozen_abi(digest = "64duaG8iUgwmgMM9y1Pdi8S9jBGoPcjS5HrE8RRfsxJJ"),
derive(AbiExample)
)]
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone)]
Expand Down
1 change: 0 additions & 1 deletion sdk/program/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use wasm_bindgen::prelude::*;

pub mod instructions;
pub mod pubkey;
pub mod system_instruction;

/// Initialize Javascript logging and panic handler
Expand Down
Loading

0 comments on commit 9e7637a

Please sign in to comment.