Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: Extract instructions-sysvar #4040

Merged
merged 3 commits into from
Dec 11, 2024
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
25 changes: 20 additions & 5 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 @@ -135,6 +135,7 @@ members = [
"sdk/hash",
"sdk/inflation",
"sdk/instruction",
"sdk/instructions-sysvar",
"sdk/keccak-hasher",
"sdk/keypair",
"sdk/logger",
Expand Down Expand Up @@ -495,6 +496,7 @@ solana-hash = { path = "sdk/hash", version = "=2.2.0", default-features = false
solana-inflation = { path = "sdk/inflation", version = "=2.2.0" }
solana-inline-spl = { path = "inline-spl", version = "=2.2.0" }
solana-instruction = { path = "sdk/instruction", version = "=2.2.0", default-features = false }
solana-instructions-sysvar = { path = "sdk/instructions-sysvar", version = "=2.2.0" }
solana-keccak-hasher = { path = "sdk/keccak-hasher", version = "=2.2.0" }
solana-keypair = { path = "sdk/keypair", version = "=2.2.0" }
solana-last-restart-slot = { path = "sdk/last-restart-slot", version = "=2.2.0" }
Expand Down
19 changes: 17 additions & 2 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 sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ assert_matches = { workspace = true }
curve25519-dalek = { workspace = true }
hex = { workspace = true }
openssl = { workspace = true }
solana-instructions-sysvar = { workspace = true, features = ["dev-context-only-utils"] }
solana-logger = { workspace = true }
solana-program = { workspace = true, features = ["dev-context-only-utils"] }
solana-sdk = { path = ".", features = ["dev-context-only-utils"] }
solana-sysvar = { workspace = true, features = ["dev-context-only-utils"] }
static_assertions = { workspace = true }
tiny-bip39 = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion sdk/benches/serialize_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
extern crate test;
use {
bincode::{deserialize, serialize},
solana_instructions_sysvar::{self as instructions, construct_instructions_data},
solana_sdk::{
instruction::{AccountMeta, Instruction},
message::{Message, SanitizedMessage},
pubkey::{self, Pubkey},
reserved_account_keys::ReservedAccountKeys,
},
solana_sysvar::instructions::{self, construct_instructions_data},
test::Bencher,
};

Expand Down
35 changes: 35 additions & 0 deletions sdk/instructions-sysvar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "solana-instructions-sysvar"
description = "Type for instruction introspection during execution of Solana programs."
documentation = "https://docs.rs/solana-instructions-sysvar"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
qualifier_attr = { workspace = true, optional = true }
solana-account-info = { workspace = true }
solana-instruction = { workspace = true, default-features = false }
solana-program-error = { workspace = true }
solana-pubkey = { workspace = true, default-features = false }
solana-sanitize = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-serialize-utils = { workspace = true }
solana-sysvar-id = { workspace = true }

[target.'cfg(not(target_os = "solana"))'.dependencies]
bitflags = { workspace = true }

[features]
dev-context-only-utils = ["dep:qualifier_attr"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
//!
//! [`secp256k1_instruction`]: https://docs.rs/solana-sdk/latest/solana_sdk/secp256k1_instruction/index.html

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::arithmetic_side_effects)]

#[cfg(feature = "dev-context-only-utils")]
use qualifier_attr::qualifiers;
#[deprecated(since = "2.2.0", note = "Use solana-instruction crate instead")]
pub use solana_instruction::{BorrowedAccountMeta, BorrowedInstruction};
pub use solana_sdk_ids::sysvar::instructions::{check_id, id, ID};
#[cfg(not(target_os = "solana"))]
use {
bitflags::bitflags,
solana_instruction::BorrowedInstruction,
solana_serialize_utils::{append_slice, append_u16, append_u8},
};
use {
Expand Down Expand Up @@ -284,11 +284,6 @@ mod tests {
solana_pubkey::Pubkey,
solana_sanitize::SanitizeError,
solana_sdk_ids::sysvar::instructions::id,
solana_sysvar::instructions::{
construct_instructions_data, deserialize_instruction, get_instruction_relative,
load_current_index_checked, load_instruction_at_checked, serialize_instructions,
store_current_index,
},
};

#[test]
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ solana-instruction = { workspace = true, default-features = false, features = [
"serde",
"std",
] }
solana-instructions-sysvar = { workspace = true }
solana-keccak-hasher = { workspace = true, features = ["sha3"] }
solana-last-restart-slot = { workspace = true, features = ["serde", "sysvar"] }
solana-message = { workspace = true, features = ["bincode", "blake3"] }
Expand Down
23 changes: 22 additions & 1 deletion sdk/program/src/sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ pub use solana_sysvar_id::{declare_deprecated_sysvar_id, declare_sysvar_id, Sysv
pub use {
solana_sdk_ids::sysvar::{check_id, id, ID},
solana_sysvar::{
clock, epoch_rewards, epoch_schedule, fees, instructions, is_sysvar_id, last_restart_slot,
clock, epoch_rewards, epoch_schedule, fees, is_sysvar_id, last_restart_slot,
recent_blockhashes, rent, rewards, slot_hashes, slot_history, stake_history, Sysvar,
ALL_IDS,
},
};

pub mod instructions {
#[deprecated(since = "2.2.0", note = "Use solana-instruction crate instead")]
pub use solana_instruction::{BorrowedAccountMeta, BorrowedInstruction};
#[cfg(not(target_os = "solana"))]
#[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")]
pub use solana_instructions_sysvar::construct_instructions_data;
#[cfg(all(not(target_os = "solana"), feature = "dev-context-only-utils"))]
#[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")]
pub use solana_instructions_sysvar::serialize_instructions;
#[cfg(feature = "dev-context-only-utils")]
#[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")]
pub use solana_instructions_sysvar::{deserialize_instruction, load_instruction_at};
#[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")]
pub use solana_instructions_sysvar::{
get_instruction_relative, load_current_index_checked, load_instruction_at_checked,
store_current_index, Instructions,
};
#[deprecated(since = "2.2.0", note = "Use solana-sdk-ids crate instead")]
pub use solana_sdk_ids::sysvar::instructions::{check_id, id, ID};
}
buffalojoec marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion sdk/secp256k1-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ hex = { workspace = true }
rand0-7 = { workspace = true }
solana-account-info = { workspace = true }
solana-hash = { workspace = true }
solana-instructions-sysvar = { workspace = true }
solana-keccak-hasher = { workspace = true }
solana-keypair = { workspace = true }
solana-logger = { workspace = true }
Expand All @@ -35,7 +36,6 @@ solana-program-error = { workspace = true }
solana-sdk = { path = ".." }
solana-secp256k1-program = { path = ".", features = ["dev-context-only-utils"] }
solana-signer = { workspace = true }
solana-sysvar = { workspace = true }

[features]
bincode = [
Expand Down
15 changes: 7 additions & 8 deletions sdk/secp256k1-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
//! use solana_msg::msg;
//! use solana_program_error::{ProgramError, ProgramResult};
//! use solana_sdk_ids::secp256k1_program;
//! use solana_sysvar::instructions;
//! use solana_instructions_sysvar::load_instruction_at_checked;
//!
//! /// An Ethereum address corresponding to a secp256k1 secret key that is
//! /// authorized to sign our messages.
Expand Down Expand Up @@ -354,7 +354,7 @@
//! // Load the secp256k1 instruction.
//! // `new_secp256k1_instruction` generates an instruction that must be at index 0.
//! let secp256k1_instr =
//! instructions::load_instruction_at_checked(0, instructions_sysvar_account)?;
//! solana_instructions_sysvar::load_instruction_at_checked(0, instructions_sysvar_account)?;
//!
//! // Verify it is a secp256k1 instruction.
//! // This is security-critical - what if the transaction uses an imposter secp256k1 program?
Expand Down Expand Up @@ -533,7 +533,7 @@
//! use solana_program_error::{ProgramError, ProgramResult};
//! use solana_msg::msg;
//! use solana_sdk_ids::secp256k1_program;
//! use solana_sysvar::instructions;
//! use solana_instructions_sysvar::{get_instruction_relative, load_instruction_at_checked};
//!
//! /// A struct to hold the values specified in the `SecpSignatureOffsets` struct.
//! struct SecpSignature {
Expand All @@ -553,15 +553,15 @@
//! ) -> Result<Vec<SecpSignature>, ProgramError> {
//! let mut sigs = vec![];
//! for offsets in secp256k1_defs::iter_signature_offsets(secp256k1_instr_data)? {
//! let signature_instr = instructions::load_instruction_at_checked(
//! let signature_instr = load_instruction_at_checked(
//! offsets.signature_instruction_index as usize,
//! instructions_sysvar_account,
//! )?;
//! let eth_address_instr = instructions::load_instruction_at_checked(
//! let eth_address_instr = load_instruction_at_checked(
//! offsets.eth_address_instruction_index as usize,
//! instructions_sysvar_account,
//! )?;
//! let message_instr = instructions::load_instruction_at_checked(
//! let message_instr = load_instruction_at_checked(
//! offsets.message_instruction_index as usize,
//! instructions_sysvar_account,
//! )?;
Expand Down Expand Up @@ -603,7 +603,7 @@
//! ));
//!
//! let secp256k1_instr =
//! instructions::get_instruction_relative(-1, instructions_sysvar_account)?;
//! solana_instructions_sysvar::get_instruction_relative(-1, instructions_sysvar_account)?;
//!
//! assert!(secp256k1_program::check_id(&secp256k1_instr.program_id));
//!
Expand Down Expand Up @@ -635,7 +635,6 @@
//! };
//! use solana_signer::Signer;
//! use solana_keypair::Keypair;
//! use solana_sysvar::instructions;
//! use solana_sdk::transaction::Transaction;
//!
//! /// A struct to hold the values specified in the `SecpSignatureOffsets` struct.
Expand Down
Loading
Loading