Skip to content
Merged
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
2,060 changes: 1,440 additions & 620 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ assert_matches = "1.5.0"
bincode = "1.3.3"
borsh = "0.10"
kaigan = "0.2.6"
mollusk-svm = "0.4.2"
mollusk-svm-bencher = "0.4.2"
mollusk-svm = "0.7.0"
mollusk-svm-bencher = "0.7.0"
num-derive = "0.4"
num-traits = "0.2"
serde = "1.0.228"
serde_derive = "1.0.193"
solana-account = "3.1.0"
solana-account-info = "3.0.0"
solana-bincode = "3.0.0"
solana-client = "2.3.4"
solana-config-interface = { version = "1.0.0" }
solana-config-interface = { version = "2.0.0" }
solana-hash = "3.0.0"
solana-instruction = "3.0.0"
solana-program = "2.3.0"
solana-msg = "3.0.0"
solana-program = "2.0.0"
solana-program-entrypoint = "3.0.0"
solana-program-error = "3.0.0"
solana-pubkey = "3.0.0"
solana-sdk = "2.2.1"
solana-sdk = "2.0.0"
solana-sdk-ids = "3.0.0"
solana-short-vec = "3.0.0"
solana-system-interface = "2.0.0"
solana-rent = "3.0.0"
thiserror = "2.0.17"

[workspace.metadata.spellcheck]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RUST_TOOLCHAIN_NIGHTLY = nightly-2025-02-16
SOLANA_CLI_VERSION = 2.3.4
SOLANA_CLI_VERSION = 3.0.0

nightly = +${RUST_TOOLCHAIN_NIGHTLY}

Expand Down
2 changes: 1 addition & 1 deletion clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ borsh = { workspace = true }
kaigan = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
solana-client = { workspace = true, optional = true }
solana-config-interface = { workspace = true, optional = true }
solana-config-interface = { version = "1", optional = true }
solana-program = { workspace = true, features = ["borsh"] }
solana-sdk = { workspace = true, optional = true }

Expand Down
13 changes: 11 additions & 2 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ bincode = { workspace = true }
num-derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true, features = ["derive"] }
solana-account-info = { workspace = true }
solana-bincode = { workspace = true }
solana-config-interface = { workspace = true, features = ["serde"] }
solana-program = { workspace = true }
solana-msg = { workspace = true }
solana-program-entrypoint = { workspace = true }
solana-program-error = { workspace = true }
solana-pubkey = { workspace = true }
solana-short-vec = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
mollusk-svm = { workspace = true, features = ["fuzz"] }
mollusk-svm-bencher = { workspace = true }
solana-account = { workspace = true }
solana-config-interface = { workspace = true, features = ["bincode", "serde"] }
solana-sdk = { workspace = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-rent = { workspace = true }

[lib]
crate-type = ["cdylib", "lib"]
Expand Down
43 changes: 43 additions & 0 deletions program/benches/compute_units.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
#### 2025-10-29 22:42:22.511198962 UTC

Solana CLI Version: solana-cli 3.0.7 (src:ea24c1fd; feat:3604001754, client:Agave)

| Name | CUs | Delta |
|------|------|-------|
| config_small_init_0_keys | 655 | +11 |
| config_small_init_1_keys | 1131 | +2 |
| config_small_init_5_keys | 2763 | -150 |
| config_small_init_10_keys | 4783 | -335 |
| config_small_init_25_keys | 11289 | -1,043 |
| config_small_init_37_keys | 16199 | -1,560 |
| config_small_store_0_keys | 655 | +11 |
| config_small_store_1_keys | 1414 | +4 |
| config_small_store_5_keys | 4066 | -128 |
| config_small_store_10_keys | 7361 | -288 |
| config_small_store_25_keys | 17692 | -921 |
| config_small_store_37_keys | 25662 | -1,378 |
| config_medium_init_0_keys | 655 | +11 |
| config_medium_init_1_keys | 1131 | +2 |
| config_medium_init_5_keys | 2763 | -150 |
| config_medium_init_10_keys | 4783 | -335 |
| config_medium_init_25_keys | 11289 | -1,043 |
| config_medium_init_37_keys | 16199 | -1,560 |
| config_medium_store_0_keys | 655 | +11 |
| config_medium_store_1_keys | 1414 | +4 |
| config_medium_store_5_keys | 4066 | -128 |
| config_medium_store_10_keys | 7361 | -288 |
| config_medium_store_25_keys | 17692 | -921 |
| config_medium_store_37_keys | 25662 | -1,378 |
| config_large_init_0_keys | 776 | +11 |
| config_large_init_1_keys | 1252 | +2 |
| config_large_init_5_keys | 2884 | -150 |
| config_large_init_10_keys | 4905 | -335 |
| config_large_init_25_keys | 11413 | -1,043 |
| config_large_init_37_keys | 16324 | -1,560 |
| config_large_store_0_keys | 776 | +11 |
| config_large_store_1_keys | 1535 | +4 |
| config_large_store_5_keys | 4187 | -128 |
| config_large_store_10_keys | 7483 | -288 |
| config_large_store_25_keys | 17816 | -921 |
| config_large_store_37_keys | 25787 | -1,378 |

#### 2025-07-14 17:12:46.523897668 UTC

Solana CLI Version: solana-cli 2.3.4 (src:bbf10bfb; feat:3640012085, client:Agave)
Expand Down
12 changes: 5 additions & 7 deletions program/benches/setup.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use {
mollusk_svm_bencher::Bench,
serde::Serialize,
solana_account::Account,
solana_config_interface::{instruction::store, state::ConfigKeys},
solana_sdk::{
account::Account,
hash::Hash,
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
rent::Rent,
},
solana_hash::Hash,
solana_instruction::{AccountMeta, Instruction},
solana_pubkey::Pubkey,
solana_rent::Rent,
};

/// Helper struct to convert to a `Bench`.
Expand Down
12 changes: 6 additions & 6 deletions program/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

use {
crate::{error::ConfigError, processor},
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError,
pubkey::Pubkey,
},
solana_account_info::AccountInfo,
solana_msg::msg,
solana_program_error::ProgramResult,
solana_pubkey::Pubkey,
};

solana_program::entrypoint!(process_instruction);
solana_program_entrypoint::entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
if let Err(error) = processor::process(program_id, accounts, instruction_data) {
error.print::<ConfigError>();
msg!(error.to_str::<ConfigError>());
return Err(error);
}
Ok(())
Expand Down
28 changes: 14 additions & 14 deletions program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

use {
num_derive::FromPrimitive,
solana_program::{
decode_error::DecodeError,
msg,
program_error::{PrintProgramError, ProgramError},
},
solana_program_error::{ProgramError, ToStr},
thiserror::Error,
};

/// Errors that can be returned by the Config program.
#[repr(u32)]
#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
pub enum ConfigError {
/// Instruction modified data of a read-only account.
#[error("Instruction modified data of a read-only account")]
ReadonlyDataModified,
}

impl PrintProgramError for ConfigError {
fn print<E>(&self) {
msg!(&self.to_string());
}
}

impl From<ConfigError> for ProgramError {
fn from(e: ConfigError) -> Self {
ProgramError::Custom(e as u32)
}
}

impl<T> DecodeError<T> for ConfigError {
fn type_of() -> &'static str {
"ConfigError"
impl ToStr for ConfigError {
fn to_str(&self) -> &'static str {
match self {
Self::ReadonlyDataModified => "Instruction modified data of a read-only account",
}
}
}

impl TryFrom<u32> for ConfigError {
type Error = ProgramError;
fn try_from(code: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(code).ok_or(ProgramError::InvalidArgument)
}
}
2 changes: 1 addition & 1 deletion program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mod entrypoint;
pub mod error;
pub mod processor;

solana_program::declare_id!("Config1111111111111111111111111111111111111");
solana_pubkey::declare_id!("Config1111111111111111111111111111111111111");
19 changes: 8 additions & 11 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use {
crate::error::ConfigError,
solana_account_info::AccountInfo,
solana_config_interface::state::ConfigKeys,
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError,
pubkey::Pubkey,
},
solana_msg::msg,
solana_program_error::{ProgramError, ProgramResult},
solana_pubkey::Pubkey,
std::collections::BTreeSet,
};

Expand All @@ -21,7 +21,7 @@ const MAX_INPUT_LEN: usize = 1232;
const MAX_VECTOR_LEN: usize = (MAX_INPUT_LEN - 3) / (32 + 1);

// [Core BPF]: The original Config builtin leverages the
// `solana_sdk::program_utils::limited_deserialize` method to cap the length of
// `solana_bincode::limited_deserialize` method to cap the length of
// the input buffer at `MAX_INPUT_LEN` (1232). As a result, any input buffer
// larger than `MAX_INPUT_LEN` will abort deserialization and return
// `InstructionError::InvalidInstructionData`.
Expand All @@ -40,11 +40,8 @@ const MAX_VECTOR_LEN: usize = (MAX_INPUT_LEN - 3) / (32 + 1);
fn safe_deserialize_config_keys(input: &[u8]) -> Result<ConfigKeys, ProgramError> {
match input.first() {
Some(first_byte) if *first_byte as usize <= MAX_VECTOR_LEN => {
solana_program::program_utils::limited_deserialize::<ConfigKeys>(
input,
MAX_INPUT_LEN as u64,
)
.map_err(|_| ProgramError::InvalidInstructionData)
solana_bincode::limited_deserialize::<ConfigKeys>(input, MAX_INPUT_LEN as u64)
.map_err(|_| ProgramError::InvalidInstructionData)
}
_ => Err(ProgramError::InvalidInstructionData),
}
Expand All @@ -65,7 +62,7 @@ fn safe_deserialize_config_keys(input: &[u8]) -> Result<ConfigKeys, ProgramError
// a memory allocation panic can occur, to ensure maximum backwards
// compatibility with the original builtin.
fn safe_deserialize_config_keys_from_state(input: &[u8]) -> Result<ConfigKeys, ProgramError> {
let (vector_len, offset) = solana_program::short_vec::decode_shortu16_len(input)
let (vector_len, offset) = solana_short_vec::decode_shortu16_len(input)
.map_err(|_| ProgramError::InvalidAccountData)?;
if input[offset..].len() / (32 + 1) < vector_len {
Err(ProgramError::InvalidAccountData)
Expand Down
30 changes: 14 additions & 16 deletions program/tests/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ use {
bincode::serialized_size,
mollusk_svm::{result::Check, Mollusk},
serde::{Deserialize, Serialize},
solana_account::Account,
solana_config_interface::{
instruction::{self as config_instruction},
state::ConfigKeys,
},
solana_config_program::error::ConfigError,
solana_sdk::{
account::Account,
instruction::{AccountMeta, Instruction},
program_error::ProgramError,
pubkey::Pubkey,
},
solana_instruction::{AccountMeta, Instruction},
solana_program_error::ProgramError,
solana_pubkey::Pubkey,
};

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -78,7 +76,7 @@ fn test_process_create_ok() {
&[(config, config_account)],
&[
Check::success(),
Check::compute_units(644),
Check::compute_units(655),
Check::account(&config)
.data(
&bincode::serialize(&(ConfigKeys { keys: vec![] }, MyConfig::default()))
Expand Down Expand Up @@ -106,7 +104,7 @@ fn test_process_store_ok() {
&[(config, config_account)],
&[
Check::success(),
Check::compute_units(644),
Check::compute_units(655),
Check::account(&config)
.data(&bincode::serialize(&(ConfigKeys { keys }, my_config)).unwrap())
.build(),
Expand Down Expand Up @@ -181,7 +179,7 @@ fn test_process_store_with_additional_signers() {
],
&[
Check::success(),
Check::compute_units(3_436),
Check::compute_units(3_325),
Check::account(&config)
.data(&bincode::serialize(&(ConfigKeys { keys }, my_config)).unwrap())
.build(),
Expand Down Expand Up @@ -323,7 +321,7 @@ fn test_config_updates() {
(signer0, Account::default()),
(signer1, Account::default()),
],
&[Check::success(), Check::compute_units(3_436)],
&[Check::success(), Check::compute_units(3_325)],
);

// Use this for next invoke.
Expand All @@ -341,7 +339,7 @@ fn test_config_updates() {
],
&[
Check::success(),
Check::compute_units(3_437),
Check::compute_units(3_327),
Check::account(&config)
.data(&bincode::serialize(&(ConfigKeys { keys }, new_config)).unwrap())
.build(),
Expand Down Expand Up @@ -454,7 +452,7 @@ fn test_config_update_contains_duplicates_fails() {
(signer0, Account::default()),
(signer1, Account::default()),
],
&[Check::success(), Check::compute_units(3_436)],
&[Check::success(), Check::compute_units(3_325)],
);

// Attempt update with duplicate signer inputs.
Expand Down Expand Up @@ -495,7 +493,7 @@ fn test_config_updates_requiring_config() {
&[(config, config_account), (signer0, Account::default())],
&[
Check::success(),
Check::compute_units(3_275),
Check::compute_units(3_169),
Check::account(&config)
.data(&bincode::serialize(&(ConfigKeys { keys: keys.clone() }, my_config)).unwrap())
.build(),
Expand All @@ -516,7 +514,7 @@ fn test_config_updates_requiring_config() {
],
&[
Check::success(),
Check::compute_units(3_275),
Check::compute_units(3_169),
Check::account(&config)
.data(&bincode::serialize(&(ConfigKeys { keys }, new_config)).unwrap())
.build(),
Expand Down Expand Up @@ -613,7 +611,7 @@ fn test_maximum_keys_input() {
let result = mollusk.process_and_validate_instruction(
&instruction,
&[(config, config_account)],
&[Check::success(), Check::compute_units(27_040)],
&[Check::success(), Check::compute_units(25_662)],
);

// Use this for next invoke.
Expand All @@ -626,7 +624,7 @@ fn test_maximum_keys_input() {
let result = mollusk.process_and_validate_instruction(
&instruction,
&[(config, updated_config_account)],
&[Check::success(), Check::compute_units(27_040)],
&[Check::success(), Check::compute_units(25_662)],
);

// Use this for next invoke.
Expand Down