├── sdk ├── .gitignore ├── src │ ├── log.rs │ ├── hash.rs │ ├── entrypoint.rs │ ├── transport.rs │ ├── pubkey.rs │ ├── signature.rs │ ├── entrypoint_deprecated.rs │ ├── signer │ │ ├── mod.rs │ │ └── keypair.rs │ ├── transaction.rs │ ├── native_loader.rs │ └── example_mocks.rs ├── tests │ └── test_pubkey_export.rs ├── benches │ ├── slot_hashes.rs │ ├── slot_history.rs │ └── short_vec.rs └── README.md ├── rust-toolchain.toml ├── sdk-wasm-js-tests ├── package.json ├── .gitignore ├── src │ └── lib.rs ├── Cargo.toml └── tests │ └── transaction.mjs ├── sdk-wasm-js ├── .gitignore ├── src │ ├── message.rs │ ├── lib.rs │ └── keypair.rs ├── package.json ├── README.md ├── tests │ └── keypair.mjs └── Cargo.toml ├── system-wasm-js ├── .gitignore ├── package.json └── Cargo.toml ├── rustfmt.toml ├── program ├── src │ ├── slot_hashes.rs │ ├── slot_history.rs │ ├── incinerator.rs │ ├── ed25519_program.rs │ ├── epoch_schedule.rs │ ├── lamports.rs │ ├── hash.rs │ ├── compute_units.rs │ ├── secp256k1_program.rs │ ├── bpf_loader_deprecated.rs │ ├── program_error.rs │ ├── syscalls │ │ └── mod.rs │ ├── bpf_loader.rs │ ├── instruction.rs │ └── sysvar.rs ├── tests │ └── test_pubkey_export.rs └── README.md ├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── add-team-to-ghsa.yml │ ├── backport.yml │ └── sysvar-comment.yml ├── borsh ├── src │ ├── lib.rs │ └── v1.rs └── Cargo.toml ├── genesis-config └── tests │ └── fixtures │ ├── devnet │ └── genesis.bin │ ├── testnet │ └── genesis.bin │ └── mainnet-beta │ └── genesis.bin ├── clock ├── src │ └── sysvar.rs └── Cargo.toml ├── rent ├── src │ └── sysvar.rs └── Cargo.toml ├── .gitignore ├── msg ├── src │ └── syscalls.rs └── Cargo.toml ├── nonce ├── src │ └── lib.rs └── Cargo.toml ├── slot-hashes ├── src │ └── sysvar.rs └── Cargo.toml ├── epoch-rewards ├── src │ └── sysvar.rs └── Cargo.toml ├── slot-history ├── src │ └── sysvar.rs └── Cargo.toml ├── epoch-schedule ├── src │ └── sysvar.rs └── Cargo.toml ├── scripts ├── check-fmt.sh ├── test-bench.sh ├── check-sort.sh ├── test-stable.sh ├── check-minimal-versions.sh ├── test-doc.sh ├── check-doc.sh ├── check-powerset.sh ├── check-hack.sh ├── test-miri.sh ├── check-shell.sh ├── test-wasm.sh ├── test-frozen-abi.sh ├── read-cargo-variable.sh ├── check-downstream-agave.sh ├── check-msrv.sh ├── read-rust-versions.sh ├── check-doc-features.sh ├── check-clippy.sh ├── patch-crates-no-header.sh ├── build-sbf.sh ├── check-detached-minimal-versions.sh ├── publish-rust.sh ├── check-nits.sh ├── cliff.toml ├── check-no-std.sh └── check-porcelain.sh ├── last-restart-slot ├── src │ ├── sysvar.rs │ └── lib.rs └── Cargo.toml ├── stable-layout ├── src │ ├── lib.rs │ ├── stable_ref_cell.rs │ ├── stable_rc.rs │ └── stable_slice.rs └── Cargo.toml ├── frozen-abi └── src │ ├── stable_abi.rs │ ├── hash.rs │ └── lib.rs ├── loader-v4-interface ├── src │ ├── lib.rs │ └── state.rs └── Cargo.toml ├── vote-interface └── src │ └── lib.rs ├── .clippy.toml ├── address-lookup-table-interface └── src │ ├── lib.rs │ └── error.rs ├── sanitize ├── Cargo.toml └── src │ └── lib.rs ├── native-token └── Cargo.toml ├── program-option └── Cargo.toml ├── time-utils └── Cargo.toml ├── validator-exit ├── Cargo.toml └── src │ └── lib.rs ├── program-pack └── Cargo.toml ├── precompile-error └── Cargo.toml ├── sdk-ids └── Cargo.toml ├── seed-derivable ├── Cargo.toml └── src │ └── lib.rs ├── cpi ├── src │ └── syscalls.rs └── Cargo.toml ├── atomic-u64 ├── Cargo.toml └── src │ └── lib.rs ├── serde └── Cargo.toml ├── package-metadata └── Cargo.toml ├── seed-phrase ├── Cargo.toml └── src │ └── lib.rs ├── quic-definitions └── Cargo.toml ├── program-memory └── Cargo.toml ├── sdk-macro └── Cargo.toml ├── commitment-config └── Cargo.toml ├── epoch-info ├── Cargo.toml └── src │ └── lib.rs ├── file-download └── Cargo.toml ├── derivation-path └── Cargo.toml ├── package-metadata-macro └── Cargo.toml ├── sysvar-id └── Cargo.toml ├── bincode ├── Cargo.toml └── src │ └── lib.rs ├── epoch-stake ├── Cargo.toml └── src │ └── lib.rs ├── serde-varint └── Cargo.toml ├── bls-signatures └── src │ ├── pubkey │ └── conversion.rs │ ├── signature │ └── conversion.rs │ ├── error.rs │ ├── proof_of_possession │ ├── conversion.rs │ └── points.rs │ ├── hash.rs │ └── lib.rs ├── ed25519-program └── Cargo.toml ├── presigner └── Cargo.toml ├── shred-version └── Cargo.toml ├── signer ├── Cargo.toml └── src │ └── null_signer.rs ├── program-log-macro └── Cargo.toml ├── define-syscall └── Cargo.toml ├── account-view └── Cargo.toml ├── keypair ├── src │ ├── signable.rs │ └── seed_derivable.rs └── Cargo.toml ├── epoch-rewards-hasher └── Cargo.toml ├── nonce-account └── Cargo.toml ├── inflation └── Cargo.toml ├── reward-info ├── Cargo.toml └── src │ └── lib.rs ├── system-transaction └── Cargo.toml ├── program-entrypoint └── Cargo.toml ├── signer-store └── Cargo.toml ├── message └── src │ ├── inner_instruction.rs │ ├── address_loader.rs │ └── versions │ └── sanitized.rs ├── sysvar └── src │ └── rewards.rs ├── account-info ├── src │ └── debug_account_data.rs └── Cargo.toml ├── fee-structure └── Cargo.toml ├── program-error └── Cargo.toml ├── program-log ├── Cargo.toml └── src │ └── wrapper.rs ├── serialize-utils └── Cargo.toml ├── keccak-hasher └── Cargo.toml ├── sha256-hasher └── Cargo.toml ├── cluster-type └── Cargo.toml ├── frozen-abi-macro └── Cargo.toml ├── hard-forks └── Cargo.toml ├── secp256r1-program └── Cargo.toml ├── cargo ├── short-vec └── Cargo.toml ├── big-mod-exp └── Cargo.toml ├── instruction-view └── Cargo.toml ├── blake3-hasher └── Cargo.toml ├── fee-calculator └── Cargo.toml ├── loader-v2-interface └── Cargo.toml ├── client-traits └── Cargo.toml ├── transaction-error └── Cargo.toml ├── poh-config ├── Cargo.toml └── src │ └── lib.rs ├── instruction-error └── Cargo.toml ├── feature-gate-interface ├── src │ ├── lib.rs │ ├── instruction.rs │ └── error.rs └── Cargo.toml ├── example-mocks └── Cargo.toml ├── bn254 └── Cargo.toml ├── pubkey ├── src │ └── lib.rs └── Cargo.toml ├── offchain-message └── Cargo.toml ├── compute-budget-interface └── Cargo.toml ├── system-interface └── src │ └── lib.rs ├── loader-v3-interface ├── src │ └── lib.rs └── Cargo.toml ├── instructions-sysvar └── Cargo.toml ├── secp256k1-recover └── Cargo.toml ├── instruction └── Cargo.toml ├── packet └── Cargo.toml ├── transaction └── src │ └── simple_vote_transaction_checker.rs ├── account └── Cargo.toml ├── secp256k1-program └── Cargo.toml └── hash └── Cargo.toml /sdk/.gitignore: -------------------------------------------------------------------------------- 1 | /farf/ 2 | /target/ 3 | -------------------------------------------------------------------------------- /sdk/src/log.rs: -------------------------------------------------------------------------------- 1 | pub use solana_program::log::*; 2 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.89.0" 3 | -------------------------------------------------------------------------------- /sdk-wasm-js-tests/package.json: -------------------------------------------------------------------------------- 1 | ../sdk-wasm-js/package.json -------------------------------------------------------------------------------- /sdk-wasm-js/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /package-lock.json 3 | -------------------------------------------------------------------------------- /system-wasm-js/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /package-lock.json 3 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | imports_granularity = "One" 2 | group_imports = "One" 3 | -------------------------------------------------------------------------------- /sdk-wasm-js-tests/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /package-lock.json 3 | -------------------------------------------------------------------------------- /program/src/slot_hashes.rs: -------------------------------------------------------------------------------- 1 | pub use {solana_clock::Slot, solana_slot_hashes::*}; 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | /message/ @anza-xyz/tx-metadata 2 | /transaction/ @anza-xyz/tx-metadata 3 | -------------------------------------------------------------------------------- /borsh/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(docsrs, feature(doc_cfg))] 2 | pub mod macros; 3 | pub mod v1; 4 | -------------------------------------------------------------------------------- /genesis-config/tests/fixtures/devnet/genesis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anza-xyz/solana-sdk/HEAD/genesis-config/tests/fixtures/devnet/genesis.bin -------------------------------------------------------------------------------- /genesis-config/tests/fixtures/testnet/genesis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anza-xyz/solana-sdk/HEAD/genesis-config/tests/fixtures/testnet/genesis.bin -------------------------------------------------------------------------------- /genesis-config/tests/fixtures/mainnet-beta/genesis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anza-xyz/solana-sdk/HEAD/genesis-config/tests/fixtures/mainnet-beta/genesis.bin -------------------------------------------------------------------------------- /clock/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::clock::{check_id, id, ID}; 2 | use {crate::Clock, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(Clock); 5 | -------------------------------------------------------------------------------- /program/src/slot_history.rs: -------------------------------------------------------------------------------- 1 | #[deprecated(since = "2.1.0", note = "Use `solana-slot-history` crate instead")] 2 | pub use {solana_clock::Slot, solana_slot_history::*}; 3 | -------------------------------------------------------------------------------- /rent/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::rent::{check_id, id, ID}; 2 | use {crate::Rent, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(Rent); 5 | -------------------------------------------------------------------------------- /program/src/incinerator.rs: -------------------------------------------------------------------------------- 1 | #[deprecated(since = "2.2.0", note = "Use `solana_sdk_ids::incinerator` instead")] 2 | pub use solana_sdk_ids::incinerator::{check_id, id, ID}; 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | farf/ 3 | 4 | **/*.rs.bk 5 | .cargo 6 | /config/ 7 | .cache 8 | 9 | # intellij files 10 | .idea/ 11 | /solana.iml 12 | /.vscode/ 13 | 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /msg/src/syscalls.rs: -------------------------------------------------------------------------------- 1 | /// Syscall definitions used by `solana_msg`. 2 | pub use solana_define_syscall::definitions::{ 3 | sol_log_, sol_log_64_, sol_log_compute_units_, sol_log_data, 4 | }; 5 | -------------------------------------------------------------------------------- /nonce/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(docsrs, feature(doc_cfg))] 2 | //! Durable transaction nonces. 3 | 4 | pub mod state; 5 | pub mod versions; 6 | 7 | pub const NONCED_TX_MARKER_IX_INDEX: u8 = 0; 8 | -------------------------------------------------------------------------------- /slot-hashes/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::slot_hashes::{check_id, id, ID}; 2 | use {crate::SlotHashes, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(SlotHashes); 5 | -------------------------------------------------------------------------------- /epoch-rewards/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::epoch_rewards::{check_id, id, ID}; 2 | use {crate::EpochRewards, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(EpochRewards); 5 | -------------------------------------------------------------------------------- /slot-history/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::slot_history::{check_id, id, ID}; 2 | use {crate::SlotHistory, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(SlotHistory); 5 | -------------------------------------------------------------------------------- /epoch-schedule/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::epoch_schedule::{check_id, id, ID}; 2 | use {crate::EpochSchedule, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(EpochSchedule); 5 | -------------------------------------------------------------------------------- /scripts/check-fmt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly fmt --all -- --check 9 | -------------------------------------------------------------------------------- /scripts/test-bench.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly bench -p solana-sdk 9 | -------------------------------------------------------------------------------- /scripts/check-sort.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly sort --workspace --check 9 | -------------------------------------------------------------------------------- /scripts/test-stable.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | cargo test --all --tests -- --nocapture 9 | -------------------------------------------------------------------------------- /system-wasm-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "postinstall": "npm run build", 4 | "build": "wasm-pack build --target nodejs --dev --out-dir node_modules/crate --out-name crate" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /last-restart-slot/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | pub use solana_sdk_ids::sysvar::last_restart_slot::{check_id, id, ID}; 2 | use {crate::LastRestartSlot, solana_sysvar_id::impl_sysvar_id}; 3 | 4 | impl_sysvar_id!(LastRestartSlot); 5 | -------------------------------------------------------------------------------- /program/src/ed25519_program.rs: -------------------------------------------------------------------------------- 1 | //! The [ed25519 native program][np]. 2 | //! 3 | //! [np]: https://docs.solanalabs.com/runtime/programs#ed25519-program 4 | pub use solana_sdk_ids::ed25519_program::{check_id, id, ID}; 5 | -------------------------------------------------------------------------------- /scripts/check-minimal-versions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly minimal-versions check --direct 9 | -------------------------------------------------------------------------------- /scripts/test-doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly hack test --doc --all-features -- --nocapture 9 | -------------------------------------------------------------------------------- /sdk/src/hash.rs: -------------------------------------------------------------------------------- 1 | //! Hashing with the [SHA-256] hash function, and a general [`Hash`] type. 2 | //! 3 | //! [SHA-256]: https://en.wikipedia.org/wiki/SHA-2 4 | //! [`Hash`]: struct@Hash 5 | 6 | pub use solana_program::hash::*; 7 | -------------------------------------------------------------------------------- /scripts/check-doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | export RUSTDOCFLAGS="-D warnings" 9 | ./cargo nightly hack doc --all-features 10 | -------------------------------------------------------------------------------- /scripts/check-powerset.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly hack clippy --feature-powerset --no-dev-deps -- --deny=warnings 9 | -------------------------------------------------------------------------------- /program/src/epoch_schedule.rs: -------------------------------------------------------------------------------- 1 | #[deprecated( 2 | since = "2.1.0", 3 | note = "Use solana-clock and solana-epoch-schedule crates instead." 4 | )] 5 | pub use { 6 | solana_clock::{Epoch, Slot, DEFAULT_SLOTS_PER_EPOCH}, 7 | solana_epoch_schedule::*, 8 | }; 9 | -------------------------------------------------------------------------------- /program/src/lamports.rs: -------------------------------------------------------------------------------- 1 | //! Re-exports the [`LamportsError`] type for backwards compatibility. 2 | #[deprecated( 3 | since = "2.1.0", 4 | note = "Use solana_instruction_error::LamportsError instead" 5 | )] 6 | pub use solana_instruction_error::LamportsError; 7 | -------------------------------------------------------------------------------- /scripts/check-hack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly hack check --all-targets --locked --features frozen-abi --ignore-unknown-features 9 | -------------------------------------------------------------------------------- /sdk/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! The Rust-based BPF program entrypoint supported by the latest BPF loader. 2 | //! 3 | //! For more information see the [`bpf_loader`] module. 4 | //! 5 | //! [`bpf_loader`]: crate::bpf_loader 6 | 7 | pub use solana_program::entrypoint::*; 8 | -------------------------------------------------------------------------------- /sdk/src/transport.rs: -------------------------------------------------------------------------------- 1 | //! Defines the [`TransportError`] type. 2 | 3 | #![cfg(feature = "full")] 4 | #[deprecated(since = "2.1.0", note = "Use solana_transaction_error crate instead")] 5 | pub use solana_transaction_error::{TransportError, TransportResult as Result}; 6 | -------------------------------------------------------------------------------- /sdk/src/pubkey.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "full")] 2 | pub use solana_pubkey::new_rand; 3 | #[cfg(target_os = "solana")] 4 | pub use solana_pubkey::syscalls; 5 | pub use solana_pubkey::{ 6 | bytes_are_curve_point, ParsePubkeyError, Pubkey, PubkeyError, MAX_SEEDS, MAX_SEED_LEN, 7 | PUBKEY_BYTES, 8 | }; 9 | -------------------------------------------------------------------------------- /stable-layout/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Types with stable memory layouts 2 | //! 3 | //! Internal use only; here be dragons! 4 | #![cfg_attr(docsrs, feature(doc_cfg))] 5 | 6 | pub mod stable_instruction; 7 | pub mod stable_rc; 8 | pub mod stable_ref_cell; 9 | pub mod stable_slice; 10 | pub mod stable_vec; 11 | -------------------------------------------------------------------------------- /frozen-abi/src/stable_abi.rs: -------------------------------------------------------------------------------- 1 | use rand::{distr::StandardUniform, Rng, RngCore}; 2 | 3 | pub trait StableAbi: Sized { 4 | fn random(rng: &mut impl RngCore) -> Self 5 | where 6 | StandardUniform: rand::distr::Distribution, 7 | { 8 | rng.random::() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /scripts/test-miri.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | # miri is very slow; so only run very few of selective tests! 8 | ./cargo nightly miri test -p solana-hash -p solana-account-info -p solana-account-view 9 | -------------------------------------------------------------------------------- /sdk-wasm-js/src/message.rs: -------------------------------------------------------------------------------- 1 | use wasm_bindgen::prelude::wasm_bindgen; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Default, Debug, PartialEq, Eq, Clone)] 5 | pub struct Message { 6 | pub(crate) inner: solana_message::Message, 7 | } 8 | 9 | crate::conversion::impl_inner_conversion!(Message, solana_message::Message); 10 | -------------------------------------------------------------------------------- /scripts/check-shell.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Reference: https://github.com/koalaman/shellcheck/wiki/Directive 4 | set -eo pipefail 5 | here="$(dirname "$0")" 6 | src_root="$(readlink -f "${here}/..")" 7 | cd "${src_root}" 8 | 9 | set -x 10 | git ls-files -- '*.sh' | xargs shellcheck --color=always --external-sources --shell=bash 11 | -------------------------------------------------------------------------------- /sdk/tests/test_pubkey_export.rs: -------------------------------------------------------------------------------- 1 | // Simple test to make sure we haven't broken the re-export of the pubkey macro in solana_sdk 2 | #[test] 3 | fn test_sdk_pubkey_export() { 4 | assert_eq!( 5 | solana_sdk::pubkey!("ZkTokenProof1111111111111111111111111111111"), 6 | solana_pubkey::pubkey!("ZkTokenProof1111111111111111111111111111111") 7 | ); 8 | } 9 | -------------------------------------------------------------------------------- /scripts/test-wasm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ( 9 | cd sdk-wasm-js 10 | npm install 11 | npm test 12 | ) 13 | 14 | ( 15 | cd sdk-wasm-js-tests 16 | npm install 17 | npm test 18 | ) 19 | 20 | ( 21 | cd system-wasm-js 22 | npm install 23 | ) 24 | -------------------------------------------------------------------------------- /program/src/hash.rs: -------------------------------------------------------------------------------- 1 | //! Hashing with the [SHA-256] hash function, and a general [`Hash`] type. 2 | //! 3 | //! [SHA-256]: https://en.wikipedia.org/wiki/SHA-2 4 | //! [`Hash`]: struct@Hash 5 | 6 | #[cfg(not(target_os = "solana"))] 7 | pub use solana_sha256_hasher::Hasher; 8 | pub use { 9 | solana_hash::{Hash, ParseHashError, HASH_BYTES}, 10 | solana_sha256_hasher::{hash, hashv}, 11 | }; 12 | -------------------------------------------------------------------------------- /scripts/test-frozen-abi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ./cargo nightly hack --features frozen-abi --ignore-unknown-features test --lib -- test_abi_digest --nocapture 9 | ./cargo nightly hack --features frozen-abi --ignore-unknown-features test --lib -- test_api_digest --nocapture 10 | -------------------------------------------------------------------------------- /scripts/read-cargo-variable.sh: -------------------------------------------------------------------------------- 1 | # source this file 2 | 3 | readCargoVariable() { 4 | declare variable="$1" 5 | declare Cargo_toml="$2" 6 | 7 | while read -r name equals value _; do 8 | if [[ $name = "$variable" && $equals = = ]]; then 9 | echo "${value//\"/}" 10 | return 11 | fi 12 | done < <(cat "$Cargo_toml") 13 | echo "Unable to locate $variable in $Cargo_toml" 1>&2 14 | } 15 | -------------------------------------------------------------------------------- /loader-v4-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! The v4 built-in loader program. 2 | //! 3 | //! This is the loader of the program runtime v2. 4 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 5 | #![cfg_attr(docsrs, feature(doc_cfg))] 6 | 7 | pub mod instruction; 8 | pub mod state; 9 | 10 | /// Cooldown before a program can be un-/redeployed again 11 | pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 1; 12 | -------------------------------------------------------------------------------- /program/src/compute_units.rs: -------------------------------------------------------------------------------- 1 | /// Return the remaining compute units the program may consume 2 | #[inline] 3 | pub fn sol_remaining_compute_units() -> u64 { 4 | #[cfg(target_os = "solana")] 5 | unsafe { 6 | crate::syscalls::sol_remaining_compute_units() 7 | } 8 | 9 | #[cfg(not(target_os = "solana"))] 10 | { 11 | crate::program_stubs::sol_remaining_compute_units() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vote-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(docsrs, feature(doc_cfg))] 2 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 3 | //! The [vote native program][np]. 4 | //! 5 | //! [np]: https://docs.solanalabs.com/runtime/programs#vote-program 6 | 7 | pub mod authorized_voters; 8 | pub mod error; 9 | pub mod instruction; 10 | pub mod state; 11 | 12 | pub mod program { 13 | pub use solana_sdk_ids::vote::{check_id, id, ID}; 14 | } 15 | -------------------------------------------------------------------------------- /.clippy.toml: -------------------------------------------------------------------------------- 1 | too-many-arguments-threshold = 9 2 | 3 | # Disallow specific methods from being used 4 | disallowed-methods = [ 5 | { path = "std::net::UdpSocket::bind", reason = "Use solana_net_utils::bind_with_config, bind_to, etc instead for proper socket configuration." }, 6 | { path = "tokio::net::UdpSocket::bind", reason = "Use solana_net_utils::bind_to_async or bind_to_with_config_non_blocking instead for proper socket configuration." }, 7 | ] 8 | -------------------------------------------------------------------------------- /sdk/src/signature.rs: -------------------------------------------------------------------------------- 1 | //! Functionality for public and private keys. 2 | #![cfg(feature = "full")] 3 | 4 | // legacy module paths 5 | #[deprecated( 6 | since = "2.2.0", 7 | note = "Use solana_keypair::signable::Signable instead." 8 | )] 9 | pub use solana_keypair::signable::Signable; 10 | pub use { 11 | crate::signer::{keypair::*, null_signer::*, presigner::*, *}, 12 | solana_signature::{ParseSignatureError, Signature, SIGNATURE_BYTES}, 13 | }; 14 | -------------------------------------------------------------------------------- /scripts/check-downstream-agave.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | rm -rf ./target/downstream/agave 9 | mkdir -p ./target/downstream 10 | cd ./target/downstream 11 | git clone --depth 1 https://github.com/anza-xyz/agave.git --single-branch --branch=master 12 | cd ./agave 13 | 14 | ../../../scripts/patch-crates-no-header.sh . ../../.. 15 | cargo check 16 | -------------------------------------------------------------------------------- /sdk-wasm-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "chai": "^4.3.4", 4 | "mocha": "^9.1.2", 5 | "prettier": "^2.4.1" 6 | }, 7 | "scripts": { 8 | "postinstall": "npm run build", 9 | "build": "wasm-pack build --target nodejs --dev --out-dir node_modules/crate --out-name crate", 10 | "pretty": "prettier --check 'tests/*.mjs'", 11 | "pretty:fix": "prettier --write 'tests/*.mjs'", 12 | "test": "mocha 'tests/*.mjs'" 13 | } 14 | } -------------------------------------------------------------------------------- /address-lookup-table-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | //! The [address lookup table program][np]. 4 | //! 5 | //! [np]: https://docs.solanalabs.com/runtime/programs#address-lookup-table-program 6 | 7 | pub mod error; 8 | pub mod instruction; 9 | pub mod state; 10 | 11 | pub mod program { 12 | pub use solana_sdk_ids::address_lookup_table::{check_id, id, ID}; 13 | } 14 | -------------------------------------------------------------------------------- /sanitize/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sanitize" 3 | description = "Solana Message Sanitization" 4 | documentation = "https://docs.rs/solana-sanitize" 5 | rust-version = "1.81.0" 6 | version = "3.0.1" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | -------------------------------------------------------------------------------- /sdk/src/entrypoint_deprecated.rs: -------------------------------------------------------------------------------- 1 | //! The Rust-based BPF program entrypoint supported by the original BPF loader. 2 | //! 3 | //! The original BPF loader is deprecated and exists for backwards-compatibility 4 | //! reasons. This module should not be used by new programs. 5 | //! 6 | //! For more information see the [`bpf_loader_deprecated`] module. 7 | //! 8 | //! [`bpf_loader_deprecated`]: crate::bpf_loader_deprecated 9 | 10 | pub use solana_program::entrypoint_deprecated::*; 11 | -------------------------------------------------------------------------------- /native-token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-native-token" 3 | description = "Definitions for the native SOL token and its fractional lamports." 4 | documentation = "https://docs.rs/solana-native-token" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | -------------------------------------------------------------------------------- /program-option/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-option" 3 | description = "A C representation of Rust's Option, used in Solana programs." 4 | documentation = "https://docs.rs/solana-program-option" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | -------------------------------------------------------------------------------- /time-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-time-utils" 3 | description = "`std::time` utilities for Solana" 4 | documentation = "https://docs.rs/solana-time-utils" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [lints] 16 | workspace = true 17 | -------------------------------------------------------------------------------- /validator-exit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-validator-exit" 3 | description = "Solana validator exit handling." 4 | documentation = "https://docs.rs/solana-validator-exit" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [lints] 16 | workspace = true 17 | -------------------------------------------------------------------------------- /program/tests/test_pubkey_export.rs: -------------------------------------------------------------------------------- 1 | use { 2 | solana_program::{pubkey, pubkey::Pubkey}, 3 | std::str::FromStr, 4 | }; 5 | 6 | // solana_program::pubkey refers to both a module and a macro. 7 | // This test demonstrates that both imports are working 8 | #[test] 9 | fn test_pubkey_import() { 10 | let pk = pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"); 11 | assert_eq!( 12 | pk, 13 | Pubkey::from_str("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").unwrap() 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /program/src/secp256k1_program.rs: -------------------------------------------------------------------------------- 1 | //! The [secp256k1 native program][np]. 2 | //! 3 | //! [np]: https://docs.solanalabs.com/runtime/programs#secp256k1-program 4 | //! 5 | //! Constructors for secp256k1 program instructions, and documentation on the 6 | //! program's usage can be found in [`solana_sdk::secp256k1_instruction`]. 7 | //! 8 | //! [`solana_sdk::secp256k1_instruction`]: https://docs.rs/solana-sdk/latest/solana_sdk/secp256k1_instruction/index.html 9 | pub use solana_sdk_ids::secp256k1_program::{check_id, id, ID}; 10 | -------------------------------------------------------------------------------- /program-pack/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-pack" 3 | description = "Solana Pack serialization trait." 4 | documentation = "https://docs.rs/solana-program-pack" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-program-error = { workspace = true } 17 | -------------------------------------------------------------------------------- /last-restart-slot/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Information about the last restart slot (hard fork). 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | 4 | #[cfg(feature = "sysvar")] 5 | pub mod sysvar; 6 | 7 | use solana_sdk_macro::CloneZeroed; 8 | 9 | #[repr(C)] 10 | #[cfg_attr( 11 | feature = "serde", 12 | derive(serde_derive::Deserialize, serde_derive::Serialize) 13 | )] 14 | #[derive(Debug, CloneZeroed, PartialEq, Eq, Default)] 15 | pub struct LastRestartSlot { 16 | /// The last restart `Slot`. 17 | pub last_restart_slot: u64, 18 | } 19 | -------------------------------------------------------------------------------- /sdk/src/signer/mod.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "full")] 2 | #[deprecated(since = "2.2.0", note = "Use `solana-presigner` crate instead")] 3 | pub use solana_presigner as presigner; 4 | #[deprecated(since = "2.2.0", note = "Use `solana-seed-derivable` crate instead")] 5 | pub use solana_seed_derivable::SeedDerivable; 6 | #[deprecated(since = "2.2.0", note = "Use `solana-signer` crate instead")] 7 | pub use solana_signer::{ 8 | null_signer, signers, unique_signers, EncodableKey, EncodableKeypair, Signer, SignerError, 9 | }; 10 | pub mod keypair; 11 | -------------------------------------------------------------------------------- /borsh/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-borsh" 3 | description = "Solana Borsh utilities" 4 | documentation = "https://docs.rs/solana-borsh" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | borsh = { workspace = true, features = ["std"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /precompile-error/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-precompile-error" 3 | description = "Solana PrecompileError type" 4 | documentation = "https://docs.rs/solana-precompile-error" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [dependencies] 17 | num-traits = { workspace = true } 18 | -------------------------------------------------------------------------------- /sdk-ids/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sdk-ids" 3 | description = "Solana SDK IDs" 4 | documentation = "https://docs.rs/solana-sdk-ids" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-address = { workspace = true, features = ["decode"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /seed-derivable/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-seed-derivable" 3 | description = "Solana trait defining the interface by which keys are derived." 4 | documentation = "https://docs.rs/solana-seed-derivable" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-derivation-path = { workspace = true } 17 | -------------------------------------------------------------------------------- /cpi/src/syscalls.rs: -------------------------------------------------------------------------------- 1 | /// Syscall definitions used by `solana_cpi`. 2 | pub use solana_define_syscall::definitions::{ 3 | sol_invoke_signed_c, sol_invoke_signed_rust, sol_set_return_data, 4 | }; 5 | use solana_pubkey::Pubkey; 6 | 7 | #[deprecated( 8 | since = "3.1.0", 9 | note = "Use `solana_define_syscall::definitions::sol_get_return_data` instead" 10 | )] 11 | pub unsafe fn sol_get_return_data(data: *mut u8, length: u64, program_id: *mut Pubkey) -> u64 { 12 | solana_define_syscall::definitions::sol_get_return_data(data, length, program_id as *mut u8) 13 | } 14 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: cargo 9 | directory: "/" 10 | schedule: 11 | interval: daily 12 | time: "08:00" 13 | timezone: UTC 14 | open-pull-requests-limit: 0 15 | -------------------------------------------------------------------------------- /atomic-u64/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-atomic-u64" 3 | description = "Solana atomic u64 implementation. For internal use only." 4 | documentation = "https://docs.rs/solana-atomic-u64" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [target.'cfg(not(target_pointer_width = "64"))'.dependencies] 16 | parking_lot = { workspace = true } 17 | -------------------------------------------------------------------------------- /serde/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-serde" 3 | description = "Solana serde helpers" 4 | documentation = "https://docs.rs/solana-serde" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | serde = { workspace = true } 17 | 18 | [dev-dependencies] 19 | bincode = { workspace = true } 20 | serde_derive = { workspace = true } 21 | -------------------------------------------------------------------------------- /borsh/src/v1.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | //! Utilities for the [borsh] serialization format, version 1. 3 | //! 4 | //! [borsh]: https://borsh.io/ 5 | use { 6 | crate::macros::{ 7 | impl_get_instance_packed_len, impl_get_packed_len_v1, impl_try_from_slice_unchecked, 8 | }, 9 | borsh::io, 10 | }; 11 | 12 | impl_get_packed_len_v1!(borsh); 13 | impl_try_from_slice_unchecked!(borsh, io); 14 | impl_get_instance_packed_len!(borsh, io); 15 | 16 | #[cfg(test)] 17 | mod tests { 18 | use {crate::macros::impl_tests, borsh::io}; 19 | impl_tests!(borsh, io); 20 | } 21 | -------------------------------------------------------------------------------- /package-metadata/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-package-metadata" 3 | description = "Solana Package Metadata" 4 | documentation = "https://docs.rs/solana-package-metadata" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-package-metadata-macro = { workspace = true } 17 | solana-pubkey = { workspace = true, features = ["std"] } 18 | -------------------------------------------------------------------------------- /seed-phrase/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-seed-phrase" 3 | description = "Solana functions for generating keypairs from seed phrases." 4 | documentation = "https://docs.rs/solana-seed-phrase" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | hmac = { workspace = true } 17 | pbkdf2 = { workspace = true } 18 | sha2 = { workspace = true } 19 | -------------------------------------------------------------------------------- /quic-definitions/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-quic-definitions" 3 | description = "Definitions related to Solana over QUIC." 4 | documentation = "https://docs.rs/solana-quic-definitions" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [dependencies] 17 | solana-keypair = { workspace = true } 18 | 19 | [lints] 20 | workspace = true 21 | -------------------------------------------------------------------------------- /.github/workflows/add-team-to-ghsa.yml: -------------------------------------------------------------------------------- 1 | name: Add Security Team to GHSAs 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "0 * * * *" 7 | 8 | jobs: 9 | add-team-to-ghsa: 10 | if: github.repository == 'anza-xyz/solana-sdk' 11 | runs-on: ubuntu-24.04 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | with: 16 | ref: master 17 | - name: Run script 18 | shell: bash 19 | env: 20 | GH_TOKEN: ${{ secrets.GHSA_ADD_SECURITY_INCIDENT_RESPONSE }} 21 | run: | 22 | .github/scripts/add-team-to-ghsa.sh 23 | -------------------------------------------------------------------------------- /sdk/src/signer/keypair.rs: -------------------------------------------------------------------------------- 1 | #[deprecated(since = "2.2.0", note = "Use `solana-keypair` crate instead")] 2 | pub use solana_keypair::{ 3 | keypair_from_seed, keypair_from_seed_phrase_and_passphrase, read_keypair, read_keypair_file, 4 | seed_derivable::keypair_from_seed_and_derivation_path, write_keypair, write_keypair_file, 5 | Keypair, 6 | }; 7 | #[deprecated(since = "2.2.0", note = "Use `solana-seed-phrase` crate instead")] 8 | pub use solana_seed_phrase::generate_seed_from_seed_phrase_and_passphrase; 9 | #[deprecated(since = "2.2.0", note = "Use `solana-signer` crate instead")] 10 | pub use solana_signer::*; 11 | -------------------------------------------------------------------------------- /msg/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-msg" 3 | description = "Solana msg macro." 4 | documentation = "https://docs.rs/solana-msg" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | default = ["std"] 17 | alloc = [] 18 | std = ["alloc"] 19 | 20 | [target.'cfg(target_os = "solana")'.dependencies] 21 | solana-define-syscall = { workspace = true } 22 | 23 | [lints] 24 | workspace = true 25 | -------------------------------------------------------------------------------- /program-memory/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-memory" 3 | description = "Basic low-level memory operations for Solana." 4 | documentation = "https://docs.rs/solana-program-memory" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 16 | solana-define-syscall = { workspace = true } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /seed-phrase/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Functions for generating keypairs from seed phrases. 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | use hmac::Hmac; 4 | 5 | pub fn generate_seed_from_seed_phrase_and_passphrase( 6 | seed_phrase: &str, 7 | passphrase: &str, 8 | ) -> Vec { 9 | const PBKDF2_ROUNDS: u32 = 2048; 10 | const PBKDF2_BYTES: usize = 64; 11 | 12 | let salt = format!("mnemonic{passphrase}"); 13 | 14 | let mut seed = vec![0u8; PBKDF2_BYTES]; 15 | pbkdf2::pbkdf2::>( 16 | seed_phrase.as_bytes(), 17 | salt.as_bytes(), 18 | PBKDF2_ROUNDS, 19 | &mut seed, 20 | ); 21 | seed 22 | } 23 | -------------------------------------------------------------------------------- /sdk-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sdk-macro" 3 | description = "Solana SDK Macro" 4 | documentation = "https://docs.rs/solana-sdk-macro" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [lib] 16 | proc-macro = true 17 | 18 | [dependencies] 19 | bs58 = { workspace = true, features = ["alloc"] } 20 | proc-macro2 = { workspace = true } 21 | quote = { workspace = true } 22 | syn = { workspace = true, features = ["full"] } 23 | -------------------------------------------------------------------------------- /frozen-abi/src/hash.rs: -------------------------------------------------------------------------------- 1 | use { 2 | sha2::{Digest, Sha256}, 3 | std::fmt, 4 | }; 5 | 6 | const HASH_BYTES: usize = 32; 7 | #[derive(AbiExample)] 8 | pub struct Hash(pub [u8; HASH_BYTES]); 9 | 10 | #[derive(Default)] 11 | pub struct Hasher { 12 | hasher: Sha256, 13 | } 14 | 15 | impl Hasher { 16 | pub fn hash(&mut self, val: &[u8]) { 17 | self.hasher.update(val); 18 | } 19 | pub fn result(self) -> Hash { 20 | Hash(self.hasher.finalize().into()) 21 | } 22 | } 23 | 24 | impl fmt::Display for Hash { 25 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 26 | write!(f, "{}", bs58::encode(self.0).into_string()) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /commitment-config/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-commitment-config" 3 | description = "Solana commitment config." 4 | documentation = "https://docs.rs/solana-commitment-config" 5 | version = "3.1.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [features] 17 | serde = ["dep:serde", "dep:serde_derive"] 18 | 19 | [dependencies] 20 | serde = { workspace = true, optional = true } 21 | serde_derive = { workspace = true, optional = true } 22 | -------------------------------------------------------------------------------- /epoch-info/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-epoch-info" 3 | description = "Information about a Solana epoch." 4 | documentation = "https://docs.rs/solana-epoch-info" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | serde = ["dep:serde", "dep:serde_derive"] 17 | 18 | [dependencies] 19 | serde = { workspace = true, optional = true } 20 | serde_derive = { workspace = true, optional = true } 21 | 22 | [lints] 23 | workspace = true 24 | -------------------------------------------------------------------------------- /file-download/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-file-download" 3 | description = "Solana File Download Utility" 4 | documentation = "https://docs.rs/solana-file-download" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | console = { workspace = true } 17 | indicatif = { workspace = true } 18 | log = { workspace = true } 19 | reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] } 20 | -------------------------------------------------------------------------------- /sdk/benches/slot_hashes.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | extern crate test; 4 | use { 5 | solana_sdk::{ 6 | account::{create_account_for_test, from_account}, 7 | hash::Hash, 8 | slot_hashes::{Slot, SlotHashes, MAX_ENTRIES}, 9 | }, 10 | test::Bencher, 11 | }; 12 | 13 | #[bench] 14 | fn bench_to_from_account(b: &mut Bencher) { 15 | let mut slot_hashes = SlotHashes::new(&[]); 16 | for i in 0..MAX_ENTRIES { 17 | slot_hashes.add(i as Slot, Hash::default()); 18 | } 19 | b.iter(|| { 20 | let account = create_account_for_test(&slot_hashes); 21 | slot_hashes = from_account::(&account).unwrap(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /program/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Solana 4 | 5 |

6 | 7 | # Solana Program 8 | 9 | Use the Solana Program Crate to write on-chain programs in Rust. If writing client-side applications, use the [Solana SDK Crate](https://crates.io/crates/solana-sdk) instead. 10 | 11 | More information about Solana is available in the [Solana documentation](https://solana.com/docs). 12 | 13 | [Solana Program Library](https://github.com/solana-labs/solana-program-library) provides examples of how to use this crate. 14 | 15 | Still have questions? Ask us on [Stack Exchange](https://sola.na/sse) 16 | -------------------------------------------------------------------------------- /sdk/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Solana 4 | 5 |

6 | 7 | # Solana SDK 8 | 9 | Use the Solana SDK Crate to write client side applications in Rust. If writing on-chain programs, use the [Solana Program Crate](https://crates.io/crates/solana-program) instead. 10 | 11 | More information about Solana is available in the [Solana documentation](https://solana.com/docs). 12 | 13 | The [Solana Program Library](https://github.com/solana-labs/solana-program-library) provides examples of how to use this crate. 14 | 15 | Still have questions? Ask us on [Stack Exchange](https://sola.na/sse) 16 | -------------------------------------------------------------------------------- /derivation-path/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-derivation-path" 3 | description = "Solana BIP44 derivation paths." 4 | documentation = "https://docs.rs/solana-derivation-path" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [dependencies] 17 | derivation-path = { workspace = true } 18 | qstring = { workspace = true } 19 | uriparse = { workspace = true } 20 | 21 | [dev-dependencies] 22 | assert_matches = { workspace = true } 23 | -------------------------------------------------------------------------------- /package-metadata-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-package-metadata-macro" 3 | description = "Solana Package Metadata Macro" 4 | documentation = "https://docs.rs/solana-package-metadata-macro" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [lib] 16 | proc-macro = true 17 | 18 | [dependencies] 19 | proc-macro2 = { workspace = true } 20 | quote = { workspace = true } 21 | syn = { workspace = true, features = ["full"] } 22 | toml = { workspace = true } 23 | -------------------------------------------------------------------------------- /scripts/check-msrv.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | source "./scripts/read-cargo-variable.sh" 9 | 10 | for cargo_toml in $(git ls-files -- '**/Cargo.toml'); do 11 | # Read the MSRV from the crate 12 | minimum_version=$(readCargoVariable rust-version "$cargo_toml" 2>/dev/null) 13 | # If the crate does not specify a rust-version, fall back to 14 | # the "program" crate MSRV 15 | if [[ -z "$minimum_version" ]]; then 16 | minimum_version=$(readCargoVariable rust-version "program/Cargo.toml") 17 | fi 18 | 19 | cargo +"$minimum_version" check --manifest-path "$cargo_toml" 20 | done 21 | -------------------------------------------------------------------------------- /sysvar-id/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sysvar-id" 3 | description = "Definition for the sysvar id trait and associated macros." 4 | documentation = "https://docs.rs/solana-sysvar-id" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [dependencies] 18 | solana-address = { workspace = true, features = ["decode"] } 19 | solana-sdk-ids = { workspace = true } 20 | 21 | [lints] 22 | workspace = true 23 | -------------------------------------------------------------------------------- /sdk-wasm-js/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Solana 4 | 5 |

6 | 7 | # Solana SDK WASM JS 8 | 9 | Use the Solana SDK WASM JS crate to build a JS package with `wasm-pack` usable in Node or browser environments. 10 | See the [Solana Program Crate](https://crates.io/crates/solana-program) instead for on-chain programs, and, the [Solana SDK Crate](https://crates.io/crates/solana-sdk) for client-side 11 | applications. 12 | 13 | More information about Solana is available in the [Solana documentation](https://solana.com/docs). 14 | 15 | Still have questions? Ask us on [Stack Exchange](https://sola.na/sse) 16 | -------------------------------------------------------------------------------- /bincode/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-bincode" 3 | description = "Solana bincode utilities" 4 | documentation = "https://docs.rs/solana-bincode" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | bincode = { workspace = true } 17 | serde_core = { workspace = true } 18 | solana-instruction-error = { workspace = true } 19 | 20 | [dev-dependencies] 21 | solana-system-interface = { workspace = true, features = ["bincode"] } 22 | 23 | [lints] 24 | workspace = true 25 | -------------------------------------------------------------------------------- /epoch-stake/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-epoch-stake" 3 | description = "Solana epoch stake syscall API" 4 | documentation = "https://docs.rs/solana-epoch-stake" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [dependencies] 18 | solana-pubkey = { workspace = true } 19 | 20 | [target.'cfg(target_os = "solana")'.dependencies] 21 | solana-define-syscall = { workspace = true } 22 | 23 | [lints] 24 | workspace = true 25 | -------------------------------------------------------------------------------- /serde-varint/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-serde-varint" 3 | description = "Solana definitions for integers that serialize to variable size" 4 | documentation = "https://docs.rs/solana-serde-varint" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | serde = { workspace = true } 17 | 18 | [dev-dependencies] 19 | bincode = { workspace = true } 20 | rand = { workspace = true } 21 | serde_derive = { workspace = true } 22 | solana-short-vec = { workspace = true } 23 | -------------------------------------------------------------------------------- /bls-signatures/src/pubkey/conversion.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(target_os = "solana"))] 2 | use { 3 | crate::pubkey::{ 4 | bytes::{ 5 | Pubkey, PubkeyCompressed, BLS_PUBLIC_KEY_AFFINE_SIZE, BLS_PUBLIC_KEY_COMPRESSED_SIZE, 6 | }, 7 | points::{AsPubkeyAffine, AsPubkeyProjective, PubkeyAffine, PubkeyProjective}, 8 | }, 9 | blstrs::{G1Affine, G1Projective}, 10 | }; 11 | 12 | #[cfg(not(target_os = "solana"))] 13 | impl_bls_conversions!( 14 | PubkeyProjective, 15 | PubkeyAffine, 16 | Pubkey, 17 | PubkeyCompressed, 18 | G1Affine, 19 | G1Projective, 20 | AsPubkeyProjective, 21 | AsPubkeyAffine, 22 | BLS_PUBLIC_KEY_COMPRESSED_SIZE, 23 | BLS_PUBLIC_KEY_AFFINE_SIZE 24 | ); 25 | -------------------------------------------------------------------------------- /ed25519-program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-ed25519-program" 3 | description = "Instructions for the Solana ed25519 native program" 4 | documentation = "https://docs.rs/solana-ed25519-program" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | bytemuck = { workspace = true } 17 | bytemuck_derive = { workspace = true } 18 | solana-instruction = { workspace = true, features = ["std"] } 19 | solana-sdk-ids = { workspace = true } 20 | 21 | [lints] 22 | workspace = true 23 | -------------------------------------------------------------------------------- /program/src/bpf_loader_deprecated.rs: -------------------------------------------------------------------------------- 1 | //! The original and now deprecated Solana BPF loader. 2 | //! 3 | //! The BPF loader is responsible for loading, finalizing, and executing BPF 4 | //! programs. 5 | //! 6 | //! This loader is deprecated, and it is strongly encouraged to build for and 7 | //! deploy to the latest BPF loader. For more information see `bpf_loader.rs` 8 | //! 9 | //! The program format may change between loaders, and it is crucial to build 10 | //! your program against the proper entrypoint semantics. All programs being 11 | //! deployed to this BPF loader must build against the deprecated entrypoint 12 | //! version located in `entrypoint_deprecated.rs`. 13 | pub use solana_sdk_ids::bpf_loader_deprecated::{check_id, id, ID}; 14 | -------------------------------------------------------------------------------- /presigner/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-presigner" 3 | description = "A Solana `Signer` implementation representing an externally-constructed `Signature`." 4 | documentation = "https://docs.rs/solana-presigner" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-pubkey = { workspace = true } 17 | solana-signature = { workspace = true, features = ["verify"] } 18 | solana-signer = { workspace = true } 19 | 20 | [dev-dependencies] 21 | solana-keypair = { workspace = true } 22 | -------------------------------------------------------------------------------- /shred-version/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-shred-version" 3 | description = "Calculation of shred versions." 4 | documentation = "https://docs.rs/solana-shred-version" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-hard-forks = { workspace = true } 17 | solana-hash = { workspace = true } 18 | solana-sha256-hasher = { workspace = true } 19 | 20 | [dev-dependencies] 21 | solana-sha256-hasher = { workspace = true, features = ["sha2"] } 22 | 23 | [lints] 24 | workspace = true 25 | -------------------------------------------------------------------------------- /signer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-signer" 3 | description = "Abstractions for Solana transaction signers. See `solana-keypair` for a concrete implementation." 4 | documentation = "https://docs.rs/solana-signer" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [dependencies] 19 | solana-pubkey = { workspace = true } 20 | solana-signature = { workspace = true } 21 | solana-transaction-error = { workspace = true } 22 | -------------------------------------------------------------------------------- /sdk/src/transaction.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "full")] 2 | #[deprecated(since = "2.2.0", note = "Use solana_transaction crate instead")] 3 | pub use solana_transaction::{ 4 | sanitized::{MessageHash, SanitizedTransaction, TransactionAccountLocks, MAX_TX_ACCOUNT_LOCKS}, 5 | uses_durable_nonce, 6 | versioned::{ 7 | sanitized::SanitizedVersionedTransaction, Legacy, TransactionVersion, VersionedTransaction, 8 | }, 9 | Transaction, TransactionVerificationMode, 10 | }; 11 | #[deprecated(since = "2.2.0", note = "Use solana_transaction_error crate instead")] 12 | pub use solana_transaction_error::{ 13 | AddressLoaderError, SanitizeMessageError, TransactionError, TransactionResult as Result, 14 | TransportError, TransportResult, 15 | }; 16 | -------------------------------------------------------------------------------- /program-log-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-log-macro" 3 | description = "Macro for solana program log utility" 4 | documentation = "https://docs.rs/solana-program-log-macro" 5 | version = "1.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | readme = "./README.md" 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [lib] 19 | proc-macro = true 20 | 21 | [dependencies] 22 | quote = { workspace = true } 23 | regex = { workspace = true } 24 | syn = { workspace = true, features = ["extra-traits", "full"] } 25 | -------------------------------------------------------------------------------- /define-syscall/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-define-syscall" 3 | description = "Solana define_syscall macro and core syscall definitions." 4 | documentation = "https://docs.rs/solana-define-syscall" 5 | version = "4.0.1" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | # static syscalls for eBPF are experimental and 17 | # not guaranteed to work 18 | unstable-static-syscalls = [] 19 | 20 | [lints.rust] 21 | unexpected_cfgs = { level = "warn", check-cfg = [ 22 | 'cfg(target_feature, values("static-syscalls"))', 23 | ] } 24 | -------------------------------------------------------------------------------- /account-view/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-account-view" 3 | description = "Lightweight representation of a runtime account" 4 | documentation = "https://docs.rs/solana-account-view" 5 | version = "1.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | copy = ["solana-address/copy"] 20 | 21 | [dependencies] 22 | solana-address = { workspace = true } 23 | solana-program-error = { workspace = true } 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /keypair/src/signable.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::Keypair, 3 | solana_address::Address, 4 | solana_signature::Signature, 5 | solana_signer::Signer, 6 | std::borrow::{Borrow, Cow}, 7 | }; 8 | 9 | pub trait Signable { 10 | fn sign(&mut self, keypair: &Keypair) { 11 | let signature = keypair.sign_message(self.signable_data().borrow()); 12 | self.set_signature(signature); 13 | } 14 | fn verify(&self) -> bool { 15 | self.get_signature() 16 | .verify(self.pubkey().as_ref(), self.signable_data().borrow()) 17 | } 18 | 19 | fn pubkey(&self) -> Address; 20 | fn signable_data(&self) -> Cow<'_, [u8]>; 21 | fn get_signature(&self) -> Signature; 22 | fn set_signature(&mut self, signature: Signature); 23 | } 24 | -------------------------------------------------------------------------------- /seed-derivable/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! The interface by which keys are derived. 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | use {solana_derivation_path::DerivationPath, std::error}; 4 | 5 | /// The `SeedDerivable` trait defines the interface by which cryptographic keys/keypairs are 6 | /// derived from byte seeds, derivation paths, and passphrases. 7 | pub trait SeedDerivable: Sized { 8 | fn from_seed(seed: &[u8]) -> Result>; 9 | fn from_seed_and_derivation_path( 10 | seed: &[u8], 11 | derivation_path: Option, 12 | ) -> Result>; 13 | fn from_seed_phrase_and_passphrase( 14 | seed_phrase: &str, 15 | passphrase: &str, 16 | ) -> Result>; 17 | } 18 | -------------------------------------------------------------------------------- /bls-signatures/src/signature/conversion.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(target_os = "solana"))] 2 | use { 3 | crate::signature::{ 4 | bytes::{ 5 | Signature, SignatureCompressed, BLS_SIGNATURE_AFFINE_SIZE, 6 | BLS_SIGNATURE_COMPRESSED_SIZE, 7 | }, 8 | points::{AsSignatureAffine, AsSignatureProjective, SignatureAffine, SignatureProjective}, 9 | }, 10 | blstrs::{G2Affine, G2Projective}, 11 | }; 12 | 13 | #[cfg(not(target_os = "solana"))] 14 | impl_bls_conversions!( 15 | SignatureProjective, 16 | SignatureAffine, 17 | Signature, 18 | SignatureCompressed, 19 | G2Affine, 20 | G2Projective, 21 | AsSignatureProjective, 22 | AsSignatureAffine, 23 | BLS_SIGNATURE_COMPRESSED_SIZE, 24 | BLS_SIGNATURE_AFFINE_SIZE 25 | ); 26 | -------------------------------------------------------------------------------- /scripts/read-rust-versions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | source "./scripts/read-cargo-variable.sh" 9 | 10 | minimum_versions=() 11 | 12 | for cargo_toml in $(git ls-files -- '**/Cargo.toml'); do 13 | # Read the MSRV from the crate 14 | minimum_version=$(readCargoVariable rust-version "$cargo_toml" 2>/dev/null) 15 | # If the crate does not specify a rust-version, fall back to 16 | # the "program" crate MSRV 17 | if [[ -z "$minimum_version" ]]; then 18 | minimum_version=$(readCargoVariable rust-version "program/Cargo.toml") 19 | fi 20 | 21 | minimum_versions+=("$minimum_version") 22 | done 23 | 24 | # Get unique versions 25 | printf '%s\n' "${minimum_versions[@]}" | sort -u 26 | -------------------------------------------------------------------------------- /epoch-rewards-hasher/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-epoch-rewards-hasher" 3 | description = "Solana epoch rewards hasher." 4 | documentation = "https://docs.rs/solana-epoch-rewards-hasher" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | siphasher = { workspace = true } 17 | solana-address = { workspace = true } 18 | solana-hash = { workspace = true } 19 | 20 | [dev-dependencies] 21 | solana-address = { workspace = true, features = ["atomic"] } 22 | solana-hash = { workspace = true, features = ["atomic"] } 23 | 24 | [lints] 25 | workspace = true 26 | -------------------------------------------------------------------------------- /.github/workflows/backport.yml: -------------------------------------------------------------------------------- 1 | name: Backport 2 | on: 3 | pull_request_target: 4 | types: 5 | - closed 6 | - labeled 7 | 8 | jobs: 9 | backport: 10 | name: Backport 11 | runs-on: ubuntu-latest 12 | # Only react to merged PRs for security reasons. 13 | # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. 14 | if: > 15 | github.event.pull_request.merged 16 | && ( 17 | github.event.action == 'closed' 18 | || ( 19 | github.event.action == 'labeled' 20 | && contains(github.event.label.name, 'backport') 21 | ) 22 | ) 23 | steps: 24 | - uses: tibdex/backport@9565281eda0731b1d20c4025c43339fb0a23812e 25 | with: 26 | github_token: ${{ secrets.GITHUB_TOKEN }} 27 | -------------------------------------------------------------------------------- /nonce-account/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-nonce-account" 3 | description = "Solana nonce account utils." 4 | documentation = "https://docs.rs/solana-nonce-account" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-account = { workspace = true, features = ["bincode"] } 17 | solana-hash = { workspace = true } 18 | solana-nonce = { workspace = true, features = ["serde"] } 19 | solana-sdk-ids = { workspace = true } 20 | 21 | [dev-dependencies] 22 | solana-fee-calculator = { workspace = true } 23 | solana-pubkey = { workspace = true, features = ["std"] } 24 | -------------------------------------------------------------------------------- /validator-exit/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Used by validators to run events on exit. 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | 4 | use std::fmt; 5 | 6 | #[derive(Default)] 7 | pub struct Exit { 8 | exited: bool, 9 | exits: Vec>, 10 | } 11 | 12 | impl Exit { 13 | pub fn register_exit(&mut self, exit: Box) { 14 | if self.exited { 15 | exit(); 16 | } else { 17 | self.exits.push(exit); 18 | } 19 | } 20 | 21 | pub fn exit(&mut self) { 22 | self.exited = true; 23 | for exit in self.exits.drain(..) { 24 | exit(); 25 | } 26 | } 27 | } 28 | 29 | impl fmt::Debug for Exit { 30 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 31 | write!(f, "{} exits", self.exits.len()) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /inflation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-inflation" 3 | description = "Configuration for Solana network inflation" 4 | documentation = "https://docs.rs/solana-inflation" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 17 | serde = ["dep:serde", "dep:serde_derive"] 18 | 19 | [dependencies] 20 | serde = { workspace = true, optional = true } 21 | serde_derive = { workspace = true, optional = true } 22 | solana-frozen-abi = { workspace = true, optional = true } 23 | solana-frozen-abi-macro = { workspace = true, optional = true } 24 | -------------------------------------------------------------------------------- /program/src/program_error.rs: -------------------------------------------------------------------------------- 1 | pub use { 2 | solana_instruction_error::{ 3 | ACCOUNT_ALREADY_INITIALIZED, ACCOUNT_BORROW_FAILED, ACCOUNT_DATA_TOO_SMALL, 4 | ACCOUNT_NOT_RENT_EXEMPT, ARITHMETIC_OVERFLOW, BORSH_IO_ERROR, 5 | BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS, CUSTOM_ZERO, ILLEGAL_OWNER, IMMUTABLE, 6 | INCORRECT_AUTHORITY, INCORRECT_PROGRAM_ID, INSUFFICIENT_FUNDS, INVALID_ACCOUNT_DATA, 7 | INVALID_ACCOUNT_DATA_REALLOC, INVALID_ACCOUNT_OWNER, INVALID_ARGUMENT, 8 | INVALID_INSTRUCTION_DATA, INVALID_SEEDS, MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED, 9 | MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED, MAX_SEED_LENGTH_EXCEEDED, 10 | MISSING_REQUIRED_SIGNATURES, NOT_ENOUGH_ACCOUNT_KEYS, UNINITIALIZED_ACCOUNT, 11 | UNSUPPORTED_SYSVAR, 12 | }, 13 | solana_program_error::ProgramError, 14 | }; 15 | -------------------------------------------------------------------------------- /reward-info/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-reward-info" 3 | description = "Solana vote reward info types" 4 | documentation = "https://docs.rs/solana-reward-info" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] 17 | serde = ["dep:serde", "dep:serde_derive"] 18 | 19 | [dependencies] 20 | serde = { workspace = true, optional = true } 21 | serde_derive = { workspace = true, optional = true } 22 | solana-frozen-abi = { workspace = true, optional = true } 23 | solana-frozen-abi-macro = { workspace = true, optional = true } 24 | -------------------------------------------------------------------------------- /sdk/src/native_loader.rs: -------------------------------------------------------------------------------- 1 | //! The native loader native program. 2 | use solana_account::{ 3 | Account, AccountSharedData, InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS, 4 | }; 5 | pub use solana_sdk_ids::native_loader::{check_id, id, ID}; 6 | 7 | /// Create an executable account with the given shared object name. 8 | pub fn create_loadable_account_with_fields( 9 | name: &str, 10 | (lamports, rent_epoch): InheritableAccountFields, 11 | ) -> AccountSharedData { 12 | AccountSharedData::from(Account { 13 | lamports, 14 | owner: id(), 15 | data: name.as_bytes().to_vec(), 16 | executable: true, 17 | rent_epoch, 18 | }) 19 | } 20 | 21 | pub fn create_loadable_account_for_test(name: &str) -> AccountSharedData { 22 | create_loadable_account_with_fields(name, DUMMY_INHERITABLE_ACCOUNT_FIELDS) 23 | } 24 | -------------------------------------------------------------------------------- /stable-layout/src/stable_ref_cell.rs: -------------------------------------------------------------------------------- 1 | //! Ensure RefCell has a stable layout 2 | 3 | #[cfg(test)] 4 | mod tests { 5 | use std::{ 6 | cell::RefCell, 7 | mem::{align_of, size_of}, 8 | }; 9 | 10 | #[test] 11 | fn test_memory_layout() { 12 | assert_eq!(align_of::>(), 8); 13 | assert_eq!(size_of::>(), 8 + 4 + /* padding */4); 14 | 15 | let value = 42; 16 | let refcell = RefCell::new(value); 17 | let _borrow = refcell.borrow(); // used to increment borrow count 18 | 19 | let addr_refcell = &refcell as *const _ as usize; 20 | let addr_borrow = addr_refcell; 21 | let addr_value = addr_refcell + 8; 22 | assert_eq!(unsafe { *(addr_borrow as *const isize) }, 1); 23 | assert_eq!(unsafe { *(addr_value as *const i32) }, 42); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /system-transaction/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-system-transaction" 3 | description = "Functionality for creating system transactions." 4 | documentation = "https://docs.rs/solana-system-transaction" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-hash = { workspace = true } 17 | solana-keypair = { workspace = true } 18 | solana-message = { workspace = true } 19 | solana-pubkey = { workspace = true } 20 | solana-signer = { workspace = true } 21 | solana-system-interface = { workspace = true, features = ["bincode"] } 22 | solana-transaction = { workspace = true, features = ["bincode"] } 23 | -------------------------------------------------------------------------------- /program-entrypoint/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-entrypoint" 3 | description = "The Solana BPF program entrypoint supported by the latest BPF loader." 4 | documentation = "https://docs.rs/solana-program-entrypoint" 5 | version = "3.1.1" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | rust-version = "1.81.0" 13 | 14 | [package.metadata.docs.rs] 15 | targets = ["x86_64-unknown-linux-gnu"] 16 | 17 | [dependencies] 18 | solana-account-info = { workspace = true } 19 | solana-define-syscall = { workspace = true } 20 | solana-program-error = { workspace = true } 21 | solana-pubkey = { workspace = true, default-features = false } 22 | 23 | [dev-dependencies] 24 | solana-msg = { workspace = true, features = ["std"] } 25 | -------------------------------------------------------------------------------- /sdk-wasm-js/tests/keypair.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { solana_program_init, Keypair } from "crate"; 3 | solana_program_init(); 4 | 5 | const KEYPAIR_LEN = 64; 6 | 7 | describe("Keypair", function () { 8 | it("works", () => { 9 | const keypair = new Keypair(); 10 | let bytes = keypair.toBytes(); 11 | expect(bytes).to.have.length(64); 12 | 13 | const recoveredKeypair = Keypair.fromBytes(bytes); 14 | expect(keypair.pubkey().equals(recoveredKeypair.pubkey())); 15 | }); 16 | 17 | it("input length validation", () => { 18 | expect(() => { 19 | Keypair.fromBytes(new Uint8Array(KEYPAIR_LEN + 1)); 20 | }).to.throw(/Invalid length for Keypair bytes/); 21 | 22 | expect(() => { 23 | Keypair.fromBytes(new Uint8Array(KEYPAIR_LEN - 1)); 24 | }).to.throw(/Invalid length for Keypair bytes/); 25 | }) 26 | }); 27 | -------------------------------------------------------------------------------- /sdk/benches/slot_history.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | extern crate test; 4 | use { 5 | solana_sdk::{ 6 | account::{create_account_for_test, from_account}, 7 | slot_history::SlotHistory, 8 | }, 9 | test::Bencher, 10 | }; 11 | 12 | #[bench] 13 | fn bench_to_from_account(b: &mut Bencher) { 14 | let mut slot_history = SlotHistory::default(); 15 | 16 | b.iter(|| { 17 | let account = create_account_for_test(&slot_history); 18 | slot_history = from_account::(&account).unwrap(); 19 | }); 20 | } 21 | 22 | #[bench] 23 | fn bench_slot_history_add_new(b: &mut Bencher) { 24 | let mut slot_history = SlotHistory::default(); 25 | 26 | let mut slot = 0; 27 | b.iter(|| { 28 | for _ in 0..5 { 29 | slot_history.add(slot); 30 | slot += 100_000; 31 | } 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /signer-store/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-signer-store" 3 | description = "Solana Signer Store" 4 | documentation = "https://docs.rs/solana-signer-store" 5 | version = "0.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [dependencies] 18 | bitvec = { workspace = true } 19 | num-derive = { workspace = true } 20 | num-traits = { workspace = true } 21 | thiserror = { workspace = true } 22 | 23 | [dev-dependencies] 24 | criterion = { workspace = true } 25 | rand = { workspace = true } 26 | 27 | [lints] 28 | workspace = true 29 | 30 | [[bench]] 31 | name = "encoding" 32 | harness = false 33 | -------------------------------------------------------------------------------- /message/src/inner_instruction.rs: -------------------------------------------------------------------------------- 1 | use crate::compiled_instruction::CompiledInstruction; 2 | 3 | #[derive(Clone, Debug, PartialEq, Eq)] 4 | #[cfg_attr( 5 | feature = "serde", 6 | derive(serde_derive::Deserialize, serde_derive::Serialize), 7 | serde(rename_all = "camelCase") 8 | )] 9 | pub struct InnerInstruction { 10 | pub instruction: CompiledInstruction, 11 | /// Invocation stack height of this instruction. Instruction stack height 12 | /// starts at 1 for transaction instructions. 13 | pub stack_height: u8, 14 | } 15 | 16 | /// An ordered list of compiled instructions that were invoked during a 17 | /// transaction instruction 18 | pub type InnerInstructions = Vec; 19 | 20 | /// A list of compiled instructions that were invoked during each instruction of 21 | /// a transaction 22 | pub type InnerInstructionsList = Vec; 23 | -------------------------------------------------------------------------------- /scripts/check-doc-features.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | err=0 9 | # Get all Cargo.toml files that don't have [package.metadata.docs.rs] specified 10 | files=$(comm -23 <(git ls-files -- '**/Cargo.toml' | sort) <(git grep -l "^\[package.metadata.docs.rs\]" | sort)) 11 | if [[ -n $files ]]; then 12 | echo "Files found without [package.metadata.docs.rs]:" 13 | echo "$files" 14 | err=1 15 | fi 16 | 17 | # Get all lib.rs files that don't have #![cfg_attr(docsrs, feature(doc_cfg))] 18 | files=$(comm -23 <(git ls-files -- '**/lib.rs' | sort) <(git grep -lE '^#!\[cfg_attr\(docsrs, feature\(doc_cfg\)\)\]' | sort)) 19 | if [[ -n $files ]]; then 20 | echo "Files found without #![cfg_attr(docsrs, feature(doc_cfg))]" 21 | echo "$files" 22 | err=1 23 | fi 24 | exit $err 25 | -------------------------------------------------------------------------------- /system-wasm-js/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-system-wasm-js" 3 | description = "Solana System Wasm JS" 4 | documentation = "https://docs.rs/solana-system-wasm-js" 5 | version = "1.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["wasm32-unknown-unknown"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [lib] 18 | crate-type = ["cdylib", "rlib"] 19 | 20 | [dependencies] 21 | solana-sdk-wasm-js = { workspace = true } 22 | solana-system-interface = { workspace = true, features = ["bincode"] } 23 | 24 | [target.'cfg(target_arch = "wasm32")'.dependencies] 25 | js-sys = { workspace = true } 26 | wasm-bindgen = { workspace = true } 27 | 28 | [lints] 29 | workspace = true 30 | -------------------------------------------------------------------------------- /sysvar/src/rewards.rs: -------------------------------------------------------------------------------- 1 | //! This sysvar is deprecated and unused. 2 | #[cfg(feature = "bincode")] 3 | use crate::SysvarSerialize; 4 | #[cfg(feature = "serde")] 5 | use serde_derive::{Deserialize, Serialize}; 6 | pub use solana_sdk_ids::sysvar::rewards::{check_id, id, ID}; 7 | use {crate::Sysvar, solana_sysvar_id::impl_sysvar_id}; 8 | 9 | impl_sysvar_id!(Rewards); 10 | 11 | #[repr(C)] 12 | #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] 13 | #[derive(Debug, Default, PartialEq)] 14 | pub struct Rewards { 15 | pub validator_point_value: f64, 16 | pub unused: f64, 17 | } 18 | impl Rewards { 19 | pub fn new(validator_point_value: f64) -> Self { 20 | Self { 21 | validator_point_value, 22 | unused: 0.0, 23 | } 24 | } 25 | } 26 | impl Sysvar for Rewards {} 27 | #[cfg(feature = "bincode")] 28 | impl SysvarSerialize for Rewards {} 29 | -------------------------------------------------------------------------------- /bls-signatures/src/error.rs: -------------------------------------------------------------------------------- 1 | use {core::convert::Infallible, thiserror::Error}; 2 | 3 | #[derive(Error, Clone, Debug, Eq, PartialEq)] 4 | pub enum BlsError { 5 | #[error("Field decode failed")] 6 | FieldDecode, 7 | #[error("Empty aggregation attempted")] 8 | EmptyAggregation, 9 | #[error("Key derivation failed")] 10 | KeyDerivation, 11 | #[error("Point representation conversion failed")] 12 | PointConversion, // TODO: could be more specific here 13 | #[error("Failed to parse from string")] 14 | ParseFromString, // TODO: update after more precise error handling 15 | #[error("Failed to parse from bytes")] 16 | ParseFromBytes, 17 | #[error("The length of inputs do not match")] 18 | InputLengthMismatch, 19 | } 20 | 21 | impl From for BlsError { 22 | fn from(_: Infallible) -> Self { 23 | unreachable!() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /message/src/address_loader.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::v0::{LoadedAddresses, MessageAddressTableLookup}, 3 | solana_transaction_error::AddressLoaderError, 4 | }; 5 | 6 | pub trait AddressLoader: Clone { 7 | fn load_addresses( 8 | self, 9 | lookups: &[MessageAddressTableLookup], 10 | ) -> Result; 11 | } 12 | 13 | #[derive(Clone)] 14 | pub enum SimpleAddressLoader { 15 | Disabled, 16 | Enabled(LoadedAddresses), 17 | } 18 | 19 | impl AddressLoader for SimpleAddressLoader { 20 | fn load_addresses( 21 | self, 22 | _lookups: &[MessageAddressTableLookup], 23 | ) -> Result { 24 | match self { 25 | Self::Disabled => Err(AddressLoaderError::Disabled), 26 | Self::Enabled(loaded_addresses) => Ok(loaded_addresses), 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /account-info/src/debug_account_data.rs: -------------------------------------------------------------------------------- 1 | //! Debug-formatting of account data. 2 | 3 | use std::{cmp, fmt}; 4 | 5 | pub(crate) const MAX_DEBUG_ACCOUNT_DATA: usize = 64; 6 | 7 | /// Format data as hex. 8 | /// 9 | /// If `data`'s length is greater than 0, add a field called "data" to `f`. The 10 | /// first 64 bytes of `data` is displayed; bytes after that are ignored. 11 | pub fn debug_account_data(data: &[u8], f: &mut fmt::DebugStruct<'_, '_>) { 12 | let data_len = cmp::min(MAX_DEBUG_ACCOUNT_DATA, data.len()); 13 | if data_len > 0 { 14 | f.field("data", &Hex(&data[..data_len])); 15 | } 16 | } 17 | 18 | pub(crate) struct Hex<'a>(pub(crate) &'a [u8]); 19 | impl fmt::Debug for Hex<'_> { 20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 21 | for &byte in self.0 { 22 | write!(f, "{byte:02x}")?; 23 | } 24 | Ok(()) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /fee-structure/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-fee-structure" 3 | description = "Solana fee structures." 4 | documentation = "https://docs.rs/solana-fee-structure" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | frozen-abi = ["dep:solana-frozen-abi"] 19 | serde = ["dep:serde", "dep:serde_derive"] 20 | 21 | [dependencies] 22 | serde = { workspace = true, optional = true } 23 | serde_derive = { workspace = true, optional = true } 24 | solana-frozen-abi = { workspace = true, optional = true, features = [ 25 | "frozen-abi", 26 | ] } 27 | 28 | [lints] 29 | workspace = true 30 | -------------------------------------------------------------------------------- /stable-layout/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-stable-layout" 3 | description = "Solana types with stable memory layouts. Internal use only." 4 | documentation = "https://docs.rs/solana-stable-layout" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [dependencies] 18 | solana-instruction = { workspace = true, default-features = false, features = [ 19 | "std", 20 | ] } 21 | solana-pubkey = { workspace = true, default-features = false } 22 | 23 | [dev-dependencies] 24 | memoffset = { workspace = true } 25 | solana-pubkey = { workspace = true, features = ["std"], default-features = false } 26 | -------------------------------------------------------------------------------- /program-error/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-error" 3 | description = "Solana ProgramError type and related definitions." 4 | documentation = "https://docs.rs/solana-program-error" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | borsh = ["dep:borsh"] 20 | serde = ["dep:serde", "dep:serde_derive"] 21 | 22 | [dependencies] 23 | borsh = { workspace = true, optional = true } 24 | serde = { workspace = true, optional = true } 25 | serde_derive = { workspace = true, optional = true } 26 | 27 | [dev-dependencies] 28 | num_enum = { workspace = true } 29 | -------------------------------------------------------------------------------- /program-log/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-program-log" 3 | description = "Lightweight log utility for Solana programs" 4 | version = "1.1.0" 5 | authors = { workspace = true } 6 | repository = { workspace = true } 7 | homepage = { workspace = true } 8 | license = { workspace = true } 9 | edition = { workspace = true } 10 | readme = "./README.md" 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [lib] 18 | crate-type = ["rlib"] 19 | 20 | [features] 21 | default = ["macro"] 22 | macro = ["dep:solana-program-log-macro"] 23 | std = [] 24 | 25 | [dependencies] 26 | solana-program-log-macro = { workspace = true, optional = true } 27 | 28 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 29 | solana-define-syscall = { workspace = true } 30 | 31 | [lints] 32 | workspace = true 33 | -------------------------------------------------------------------------------- /scripts/check-clippy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | here="$(dirname "$0")" 6 | src_root="$(readlink -f "${here}/..")" 7 | 8 | cd "${src_root}" 9 | 10 | # Use nightly clippy, as frozen-abi proc-macro generates a lot of code across 11 | # various crates in this whole monorepo (frozen-abi is enabled only under nightly 12 | # due to the use of unstable rust feature). Likewise, frozen-abi(-macro) crates' 13 | # unit tests are only compiled under nightly. 14 | # Similarly, nightly is desired to run clippy over all of bench files because 15 | # the bench itself isn't stabilized yet... 16 | # ref: https://github.com/rust-lang/rust/issues/66287 17 | ./cargo nightly clippy \ 18 | --workspace --all-targets --features frozen-abi -- \ 19 | --deny=warnings \ 20 | --deny=clippy::default_trait_access \ 21 | --deny=clippy::arithmetic_side_effects \ 22 | --deny=clippy::manual_let_else \ 23 | --deny=clippy::used_underscore_binding 24 | -------------------------------------------------------------------------------- /sdk-wasm-js-tests/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! `SystemInstruction` Javascript interface 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #![cfg(target_arch = "wasm32")] 4 | #![allow(non_snake_case)] 5 | pub use solana_sdk_wasm_js::{ 6 | address::Address, hash::Hash, instruction::Instruction, keypair::Keypair, solana_program_init, 7 | transaction::Transaction, 8 | }; 9 | use wasm_bindgen::prelude::*; 10 | 11 | #[wasm_bindgen] 12 | pub struct MyProgramInstruction; 13 | 14 | fn my_program_instruction(program_id: &solana_address::Address) -> solana_instruction::Instruction { 15 | solana_instruction::Instruction { 16 | program_id: *program_id, 17 | accounts: vec![], 18 | data: vec![], 19 | } 20 | } 21 | 22 | #[wasm_bindgen] 23 | impl MyProgramInstruction { 24 | #[wasm_bindgen(constructor)] 25 | pub fn constructor(program_id: &Address) -> Instruction { 26 | my_program_instruction(program_id).into() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /serialize-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-serialize-utils" 3 | description = "Solana helpers for reading and writing bytes." 4 | documentation = "https://docs.rs/solana-serialize-utils" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-instruction-error = { workspace = true } 17 | solana-pubkey = { workspace = true, default-features = false } 18 | solana-sanitize = { workspace = true } 19 | 20 | [dev-dependencies] 21 | bincode = { workspace = true } 22 | borsh = { workspace = true } 23 | rand = { workspace = true } 24 | serde = { workspace = true } 25 | solana-pubkey = { workspace = true, default-features = false, features = [ 26 | "borsh", 27 | "serde", 28 | ] } 29 | -------------------------------------------------------------------------------- /keccak-hasher/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-keccak-hasher" 3 | description = "Solana Keccak hashing" 4 | documentation = "https://docs.rs/solana-keccak-hasher" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | sha3 = ["dep:sha3"] 19 | 20 | [dependencies] 21 | solana-hash = { workspace = true, features = ["decode"] } 22 | 23 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 24 | solana-define-syscall = { workspace = true } 25 | 26 | [target.'cfg(not(any(target_os = "solana", target_arch = "bpf")))'.dependencies] 27 | sha3 = { workspace = true, optional = true } 28 | 29 | [lints] 30 | workspace = true 31 | -------------------------------------------------------------------------------- /slot-history/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-slot-history" 3 | description = "Types and utilities for the Solana SlotHistory sysvar." 4 | documentation = "https://docs.rs/solana-slot-history" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | serde = ["dep:serde", "dep:serde_derive", "bv/serde"] 19 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 20 | 21 | [dependencies] 22 | bv = { workspace = true } 23 | serde = { workspace = true, optional = true } 24 | serde_derive = { workspace = true, optional = true } 25 | solana-sdk-ids = { workspace = true, optional = true } 26 | solana-sysvar-id = { workspace = true, optional = true } 27 | -------------------------------------------------------------------------------- /sha256-hasher/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sha256-hasher" 3 | description = "Solana SHA256 hashing" 4 | documentation = "https://docs.rs/solana-sha256-hasher" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | sha2 = ["dep:sha2"] 17 | 18 | [dependencies] 19 | solana-hash = { workspace = true } 20 | 21 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 22 | solana-define-syscall = { workspace = true } 23 | 24 | [target.'cfg(not(any(target_os = "solana", target_arch = "bpf")))'.dependencies] 25 | sha2 = { workspace = true, optional = true } 26 | 27 | [dev-dependencies] 28 | solana-sha256-hasher = { path = ".", features = ["sha2"] } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /cluster-type/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-cluster-type" 3 | description = "Solana ClusterType enum" 4 | documentation = "https://docs.rs/solana-cluster-type" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 19 | serde = ["dep:serde", "dep:serde_derive"] 20 | 21 | [dependencies] 22 | serde = { workspace = true, optional = true } 23 | serde_derive = { workspace = true, optional = true } 24 | solana-frozen-abi = { workspace = true, optional = true } 25 | solana-frozen-abi-macro = { workspace = true, optional = true } 26 | solana-hash = { workspace = true, features = ["decode"] } 27 | -------------------------------------------------------------------------------- /frozen-abi-macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-frozen-abi-macro" 3 | description = "Solana Frozen ABI Macro" 4 | documentation = "https://docs.rs/solana-frozen-abi-macro" 5 | version = "3.2.1" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [lib] 18 | proc-macro = true 19 | 20 | [features] 21 | default = [] 22 | # activate the frozen-abi feature when we actually want to do frozen-abi testing, 23 | # otherwise leave it off because it requires nightly Rust 24 | frozen-abi = [] 25 | 26 | [dependencies] 27 | proc-macro2 = { workspace = true } 28 | quote = { workspace = true } 29 | syn = { workspace = true, features = ["full", "extra-traits"] } 30 | 31 | [lints] 32 | workspace = true 33 | -------------------------------------------------------------------------------- /last-restart-slot/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-last-restart-slot" 3 | description = "Types and utilities for the Solana LastRestartSlot sysvar." 4 | documentation = "https://docs.rs/solana-last-restart-slot" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [dependencies] 13 | serde = { workspace = true, optional = true } 14 | serde_derive = { workspace = true, optional = true } 15 | solana-sdk-ids = { workspace = true, optional = true } 16 | solana-sdk-macro = { workspace = true } 17 | solana-sysvar-id = { workspace = true, optional = true } 18 | 19 | [features] 20 | serde = ["dep:serde", "dep:serde_derive"] 21 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 22 | 23 | [package.metadata.docs.rs] 24 | targets = ["x86_64-unknown-linux-gnu"] 25 | all-features = true 26 | rustdoc-args = ["--cfg=docsrs"] 27 | -------------------------------------------------------------------------------- /sdk-wasm-js-tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sdk-wasm-js-tests" 3 | description = "Tests for using the Solana SDK Wasm JS crate" 4 | documentation = "https://docs.rs/solana-system-interface-wasm-js" 5 | publish = false 6 | version = "1.0.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [lib] 19 | crate-type = ["cdylib", "rlib"] 20 | 21 | [dependencies] 22 | solana-address = { workspace = true } 23 | solana-instruction = { workspace = true, features = ["std"] } 24 | solana-sdk-wasm-js = { workspace = true } 25 | 26 | [target.'cfg(target_arch = "wasm32")'.dependencies] 27 | js-sys = { workspace = true } 28 | wasm-bindgen = { workspace = true } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /sdk/benches/short_vec.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | extern crate test; 4 | use {bincode::deserialize, solana_short_vec::ShortVec, test::Bencher}; 5 | 6 | // Return a ShortVec with 127 bytes 7 | fn create_encoded_short_vec() -> Vec { 8 | let mut bytes = vec![127]; 9 | bytes.extend_from_slice(&[0u8; 127]); 10 | bytes 11 | } 12 | 13 | // Return a Vec with 127 bytes 14 | fn create_encoded_vec() -> Vec { 15 | let mut bytes = vec![127, 0, 0, 0, 0, 0, 0, 0]; 16 | bytes.extend_from_slice(&[0u8; 127]); 17 | bytes 18 | } 19 | 20 | #[bench] 21 | fn bench_short_vec(b: &mut Bencher) { 22 | b.iter(|| { 23 | let bytes = test::black_box(create_encoded_short_vec()); 24 | deserialize::>(&bytes).unwrap(); 25 | }); 26 | } 27 | 28 | #[bench] 29 | fn bench_vec(b: &mut Bencher) { 30 | b.iter(|| { 31 | let bytes = test::black_box(create_encoded_vec()); 32 | deserialize::>(&bytes).unwrap(); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /account-info/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-account-info" 3 | description = "Solana AccountInfo and related definitions." 4 | documentation = "https://docs.rs/solana-account-info" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:bincode", "dep:serde_core"] 19 | 20 | [dependencies] 21 | bincode = { workspace = true, optional = true } 22 | serde_core = { workspace = true, optional = true } 23 | solana-address = { workspace = true, features = ["decode"] } 24 | solana-program-error = { workspace = true } 25 | solana-program-memory = { workspace = true } 26 | 27 | [dev-dependencies] 28 | solana-address = { workspace = true, features = ["atomic"] } 29 | -------------------------------------------------------------------------------- /bls-signatures/src/proof_of_possession/conversion.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(target_os = "solana"))] 2 | use { 3 | crate::proof_of_possession::{ 4 | bytes::{ 5 | ProofOfPossession, ProofOfPossessionCompressed, BLS_PROOF_OF_POSSESSION_AFFINE_SIZE, 6 | BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, 7 | }, 8 | points::{ 9 | AsProofOfPossessionAffine, AsProofOfPossessionProjective, ProofOfPossessionAffine, 10 | ProofOfPossessionProjective, 11 | }, 12 | }, 13 | blstrs::{G2Affine, G2Projective}, 14 | }; 15 | 16 | #[cfg(not(target_os = "solana"))] 17 | impl_bls_conversions!( 18 | ProofOfPossessionProjective, 19 | ProofOfPossessionAffine, 20 | ProofOfPossession, 21 | ProofOfPossessionCompressed, 22 | G2Affine, 23 | G2Projective, 24 | AsProofOfPossessionProjective, 25 | AsProofOfPossessionAffine, 26 | BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, 27 | BLS_PROOF_OF_POSSESSION_AFFINE_SIZE 28 | ); 29 | -------------------------------------------------------------------------------- /hard-forks/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-hard-forks" 3 | description = "The list of slot boundaries at which a hard fork should occur." 4 | documentation = "https://docs.rs/solana-hard-forks" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 17 | serde = ["dep:serde", "dep:serde_derive", "serde/alloc"] 18 | 19 | [dependencies] 20 | serde = { workspace = true, optional = true } 21 | serde_derive = { workspace = true, optional = true } 22 | solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } 23 | solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /secp256r1-program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-secp256r1-program" 3 | description = "Precompile implementation for the secp256r1 elliptic curve." 4 | documentation = "https://docs.rs/solana-secp256r1" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | default = [] 20 | openssl-vendored = ["openssl/vendored"] 21 | 22 | [dependencies] 23 | bytemuck = { workspace = true, features = ["derive"] } 24 | solana-sdk-ids = { workspace = true } 25 | 26 | [target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "solana")))'.dependencies] 27 | openssl = { workspace = true } 28 | solana-instruction = { workspace = true, features = ["std"] } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /slot-hashes/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-slot-hashes" 3 | description = "Types and utilities for the Solana SlotHashes sysvar." 4 | documentation = "https://docs.rs/solana-slot-hashes" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | serde = ["dep:serde", "dep:serde_derive", "serde/alloc", "solana-hash/serde"] 17 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 18 | 19 | [dependencies] 20 | serde = { workspace = true, optional = true } 21 | serde_derive = { workspace = true, optional = true } 22 | solana-hash = { workspace = true, features = ["decode"] } 23 | solana-sdk-ids = { workspace = true, optional = true } 24 | solana-sysvar-id = { workspace = true, optional = true } 25 | 26 | [dev-dependencies] 27 | solana-sha256-hasher = { workspace = true } 28 | -------------------------------------------------------------------------------- /stable-layout/src/stable_rc.rs: -------------------------------------------------------------------------------- 1 | //! Ensure Rc has a stable memory layout 2 | 3 | #[cfg(test)] 4 | mod tests { 5 | use std::{ 6 | mem::{align_of, size_of}, 7 | rc::Rc, 8 | }; 9 | 10 | #[test] 11 | fn test_memory_layout() { 12 | assert_eq!(align_of::>(), 8); 13 | assert_eq!(size_of::>(), 8); 14 | 15 | let value = 42; 16 | let rc = Rc::new(value); 17 | let _rc2 = Rc::clone(&rc); // used to increment strong count 18 | 19 | let addr_rc = &rc as *const _ as usize; 20 | let addr_ptr = addr_rc; 21 | let addr_rcbox = unsafe { *(addr_ptr as *const *const i32) } as usize; 22 | let addr_strong = addr_rcbox; 23 | let addr_weak = addr_rcbox + 8; 24 | let addr_value = addr_rcbox + 16; 25 | assert_eq!(unsafe { *(addr_strong as *const usize) }, 2); 26 | assert_eq!(unsafe { *(addr_weak as *const usize) }, 1); 27 | assert_eq!(unsafe { *(addr_value as *const i32) }, 42); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cargo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck source=ci/rust-version.sh 4 | here=$(dirname "$0") 5 | 6 | toolchain= 7 | case "$1" in 8 | stable) 9 | source "${here}"/scripts/rust-version.sh stable 10 | # shellcheck disable=SC2054 # rust_stable is sourced from rust-version.sh 11 | toolchain="$rust_stable" 12 | shift 13 | ;; 14 | minimum) 15 | source "${here}"/scripts/rust-version.sh minimum 16 | # shellcheck disable=SC2054 # rust_stable is sourced from rust-version.sh 17 | toolchain="$rust_minimum" 18 | shift 19 | ;; 20 | nightly) 21 | source "${here}"/scripts/rust-version.sh nightly 22 | # shellcheck disable=SC2054 # rust_nightly is sourced from rust-version.sh 23 | toolchain="$rust_nightly" 24 | shift 25 | ;; 26 | *) 27 | source "${here}"/scripts/rust-version.sh stable 28 | # shellcheck disable=SC2054 # rust_stable is sourced from rust-version.sh 29 | toolchain="$rust_stable" 30 | ;; 31 | esac 32 | 33 | set -x 34 | exec cargo "+${toolchain}" "${@}" 35 | -------------------------------------------------------------------------------- /epoch-info/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | //! Information about the current epoch. 4 | //! 5 | //! As returned by the [`getEpochInfo`] RPC method. 6 | //! 7 | //! [`getEpochInfo`]: https://solana.com/docs/rpc/http/getepochinfo 8 | #![cfg_attr(docsrs, feature(doc_cfg))] 9 | 10 | #[cfg_attr( 11 | feature = "serde", 12 | derive(serde_derive::Deserialize, serde_derive::Serialize), 13 | serde(rename_all = "camelCase") 14 | )] 15 | #[derive(Clone, Debug, Eq, PartialEq)] 16 | pub struct EpochInfo { 17 | /// The current epoch 18 | pub epoch: u64, 19 | 20 | /// The current slot, relative to the start of the current epoch 21 | pub slot_index: u64, 22 | 23 | /// The number of slots in this epoch 24 | pub slots_in_epoch: u64, 25 | 26 | /// The absolute current slot 27 | pub absolute_slot: u64, 28 | 29 | /// The current block height 30 | pub block_height: u64, 31 | 32 | /// Total number of transactions processed without error since genesis 33 | pub transaction_count: Option, 34 | } 35 | -------------------------------------------------------------------------------- /short-vec/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-short-vec" 3 | description = "Solana compact serde-encoding of vectors with small length." 4 | documentation = "https://docs.rs/solana-short-vec" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 17 | 18 | [dependencies] 19 | serde_core = { workspace = true } 20 | solana-frozen-abi = { workspace = true, optional = true, features = [ 21 | "frozen-abi", 22 | ] } 23 | solana-frozen-abi-macro = { workspace = true, optional = true, features = [ 24 | "frozen-abi", 25 | ] } 26 | 27 | [dev-dependencies] 28 | assert_matches = { workspace = true } 29 | bincode = { workspace = true } 30 | serde_json = { workspace = true } 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /big-mod-exp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-big-mod-exp" 3 | description = "Solana big integer modular exponentiation" 4 | documentation = "https://docs.rs/solana-big-mod-exp" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [target.'cfg(not(target_os = "solana"))'.dependencies] 16 | num-bigint = { workspace = true } 17 | num-traits = { workspace = true } 18 | 19 | [target.'cfg(target_os = "solana")'.dependencies] 20 | solana-define-syscall = { workspace = true } 21 | 22 | [dev-dependencies] 23 | array-bytes = { workspace = true } 24 | criterion = { workspace = true } 25 | serde = { workspace = true } 26 | serde_derive = { workspace = true } 27 | serde_json = { workspace = true } 28 | 29 | [lints] 30 | workspace = true 31 | 32 | [[bench]] 33 | name = "big_mod_exp_bench" 34 | harness = false 35 | -------------------------------------------------------------------------------- /stable-layout/src/stable_slice.rs: -------------------------------------------------------------------------------- 1 | //! Ensure slice has a stable memory layout 2 | 3 | #[cfg(test)] 4 | mod tests { 5 | use std::mem::{align_of, size_of}; 6 | 7 | #[test] 8 | fn test_memory_layout() { 9 | assert_eq!(align_of::<&[i32]>(), 8); 10 | assert_eq!(size_of::<&[i32]>(), /*ptr*/ 8 + /*len*/8); 11 | 12 | let array = [11, 22, 33, 44, 55]; 13 | let slice = array.as_slice(); 14 | 15 | let addr_slice = &slice as *const _ as usize; 16 | let addr_ptr = addr_slice; 17 | let addr_len = addr_slice + 8; 18 | assert_eq!(unsafe { *(addr_len as *const usize) }, 5); 19 | 20 | let ptr_data = addr_ptr as *const *const i32; 21 | assert_eq!(unsafe { *((*ptr_data).offset(0)) }, 11); 22 | assert_eq!(unsafe { *((*ptr_data).offset(1)) }, 22); 23 | assert_eq!(unsafe { *((*ptr_data).offset(2)) }, 33); 24 | assert_eq!(unsafe { *((*ptr_data).offset(3)) }, 44); 25 | assert_eq!(unsafe { *((*ptr_data).offset(4)) }, 55); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /instruction-view/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-instruction-view" 3 | description = "Lightweight instruction representation" 4 | documentation = "https://docs.rs/solana-instruction-view" 5 | version = "1.0.0" 6 | rust-version = "1.82.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | cpi = ["dep:solana-define-syscall", "dep:solana-program-error"] 20 | slice-cpi = ["cpi"] 21 | 22 | [dependencies] 23 | solana-account-view = { workspace = true } 24 | solana-address = { workspace = true } 25 | solana-program-error = { workspace = true, optional = true } 26 | 27 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 28 | solana-define-syscall = { workspace = true, optional = true } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /scripts/patch-crates-no-header.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | # pacify shellcheck: cannot follow dynamic path 6 | # shellcheck disable=SC1090,SC1091 7 | source "$here"/patch-crates-functions.sh 8 | 9 | usage() { 10 | cat <&2 11 | USAGE: 12 | $0 [] 13 | 14 | ARGS: 15 | Path to the root of an agave repo 16 | Path to the root of a solana-sdk repo 17 | [] (Optional) Relative path to one crate to patch, ie. "address". By default, all crates are patched. 18 | EOF 19 | } 20 | 21 | agave_path="$1" 22 | if [ -z "$agave_path" ]; then 23 | usage 24 | exit 1 25 | fi 26 | 27 | solana_sdk_path="$2" 28 | if [ -z "$solana_sdk_path" ]; then 29 | usage 30 | exit 1 31 | fi 32 | 33 | crate_dir="$3" 34 | 35 | update_solana_sdk_dependencies "$agave_path" "$solana_sdk_path" "$crate_dir" 36 | patch_crates_io_solana_sdk_no_header "$agave_path"/Cargo.toml "$solana_sdk_path" "$crate_dir" 37 | -------------------------------------------------------------------------------- /clock/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-clock" 3 | description = "Solana Clock and Time Definitions" 4 | documentation = "https://docs.rs/solana-clock" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | serde = ["dep:serde", "dep:serde_derive"] 19 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 20 | 21 | [dependencies] 22 | serde = { workspace = true, optional = true } 23 | serde_derive = { workspace = true, optional = true } 24 | solana-sdk-ids = { workspace = true, optional = true } 25 | solana-sdk-macro = { workspace = true } 26 | solana-sysvar-id = { workspace = true, optional = true } 27 | 28 | [dev-dependencies] 29 | solana-clock = { path = ".", features = ["sysvar"] } 30 | static_assertions = { workspace = true } 31 | -------------------------------------------------------------------------------- /blake3-hasher/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-blake3-hasher" 3 | description = "Solana BLAKE3 hashing" 4 | documentation = "https://docs.rs/solana-blake3-hasher" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | blake3 = ["dep:blake3"] 19 | 20 | [dependencies] 21 | solana-hash = { workspace = true, features = ["decode"] } 22 | 23 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 24 | solana-define-syscall = { workspace = true } 25 | 26 | [target.'cfg(not(any(target_os = "solana", target_arch = "bpf")))'.dependencies] 27 | blake3 = { workspace = true, optional = true } 28 | 29 | [dev-dependencies] 30 | solana-blake3-hasher = { path = ".", features = ["blake3"] } 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /fee-calculator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-fee-calculator" 3 | description = "Solana transaction fee calculation" 4 | documentation = "https://docs.rs/solana-fee-calculator" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 19 | serde = ["dep:serde", "dep:serde_derive"] 20 | 21 | [dependencies] 22 | log = { workspace = true } 23 | serde = { workspace = true, optional = true } 24 | serde_derive = { workspace = true, optional = true } 25 | solana-frozen-abi = { workspace = true, optional = true } 26 | solana-frozen-abi-macro = { workspace = true, optional = true } 27 | 28 | [dev-dependencies] 29 | solana-clock = { workspace = true } 30 | static_assertions = { workspace = true } 31 | -------------------------------------------------------------------------------- /scripts/build-sbf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | build_sbf_excludes=( 9 | --exclude solana-client-traits 10 | --exclude solana-ed25519-program 11 | --exclude solana-example-mocks 12 | --exclude solana-file-download 13 | --exclude solana-genesis-config 14 | --exclude solana-keypair 15 | --exclude solana-offchain-message 16 | --exclude solana-presigner 17 | --exclude solana-quic-definitions 18 | --exclude solana-sdk-wasm-js 19 | --exclude solana-sdk-wasm-js-tests 20 | --exclude solana-secp256k1-program 21 | --exclude solana-secp256r1-program 22 | --exclude solana-system-transaction 23 | --exclude solana-system-wasm-js 24 | --exclude solana-transaction 25 | --exclude solana-sdk 26 | ) 27 | 28 | ./cargo nightly hack --workspace "${build_sbf_excludes[@]}" build-sbf 29 | 30 | # This can be added back in once the SDK upgrades to v2.3 of Agave tools 31 | #./cargo nightly build-sbf --manifest-path sdk/Cargo.toml --no-default-features 32 | -------------------------------------------------------------------------------- /loader-v2-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-loader-v2-interface" 3 | description = "Solana non-upgradable BPF loader v2 instructions." 4 | documentation = "https://docs.rs/solana-loader-v2-interface" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:solana-instruction", "serde"] 19 | serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive"] 20 | 21 | [dependencies] 22 | serde = { workspace = true, optional = true } 23 | serde_bytes = { workspace = true, optional = true } 24 | serde_derive = { workspace = true, optional = true } 25 | solana-instruction = { workspace = true, features = ["bincode", "std"], optional = true } 26 | solana-pubkey = { workspace = true } 27 | solana-sdk-ids = { workspace = true } 28 | 29 | [lints] 30 | workspace = true 31 | -------------------------------------------------------------------------------- /atomic-u64/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | pub use implementation::AtomicU64; 4 | 5 | #[cfg(target_pointer_width = "64")] 6 | mod implementation { 7 | use core::sync::atomic; 8 | 9 | pub struct AtomicU64(atomic::AtomicU64); 10 | 11 | impl AtomicU64 { 12 | pub const fn new(initial: u64) -> Self { 13 | Self(atomic::AtomicU64::new(initial)) 14 | } 15 | 16 | pub fn fetch_add(&self, v: u64) -> u64 { 17 | self.0.fetch_add(v, atomic::Ordering::Relaxed) 18 | } 19 | } 20 | } 21 | 22 | #[cfg(not(target_pointer_width = "64"))] 23 | mod implementation { 24 | use parking_lot::{const_mutex, Mutex}; 25 | 26 | pub struct AtomicU64(Mutex); 27 | 28 | impl AtomicU64 { 29 | pub const fn new(initial: u64) -> Self { 30 | Self(const_mutex(initial)) 31 | } 32 | 33 | pub fn fetch_add(&self, v: u64) -> u64 { 34 | let mut lock = self.0.lock(); 35 | let i = *lock; 36 | *lock = i + v; 37 | i 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /client-traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-client-traits" 3 | description = "Traits for Solana clients" 4 | documentation = "https://docs.rs/solana-client-traits" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-account = { workspace = true } 17 | solana-commitment-config = { workspace = true } 18 | solana-epoch-info = { workspace = true } 19 | solana-hash = { workspace = true } 20 | solana-instruction = { workspace = true } 21 | solana-keypair = { workspace = true } 22 | solana-message = { workspace = true } 23 | solana-pubkey = { workspace = true } 24 | solana-signature = { workspace = true } 25 | solana-signer = { workspace = true } 26 | solana-system-interface = { workspace = true, features = ["bincode"] } 27 | solana-transaction = { workspace = true, features = ["bincode"] } 28 | solana-transaction-error = { workspace = true } 29 | -------------------------------------------------------------------------------- /signer/src/null_signer.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::{Signer, SignerError}, 3 | solana_pubkey::Pubkey, 4 | solana_signature::Signature, 5 | }; 6 | 7 | /// NullSigner - A `Signer` implementation that always produces `Signature::default()`. 8 | /// Used as a placeholder for absentee signers whose 'Pubkey` is required to construct 9 | /// the transaction 10 | #[derive(Clone, Debug, Default)] 11 | pub struct NullSigner { 12 | pubkey: Pubkey, 13 | } 14 | 15 | impl NullSigner { 16 | pub fn new(pubkey: &Pubkey) -> Self { 17 | Self { pubkey: *pubkey } 18 | } 19 | } 20 | 21 | impl Signer for NullSigner { 22 | fn try_pubkey(&self) -> Result { 23 | Ok(self.pubkey) 24 | } 25 | 26 | fn try_sign_message(&self, _message: &[u8]) -> Result { 27 | Ok(Signature::default()) 28 | } 29 | 30 | fn is_interactive(&self) -> bool { 31 | false 32 | } 33 | } 34 | 35 | impl PartialEq for NullSigner 36 | where 37 | T: Signer, 38 | { 39 | fn eq(&self, other: &T) -> bool { 40 | self.pubkey == other.pubkey() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /scripts/check-detached-minimal-versions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | base="$(dirname "${BASH_SOURCE[0]}")" 5 | # pacify shellcheck: cannot follow dynamic path 6 | # shellcheck disable=SC1090,SC1091 7 | source "$base/read-cargo-variable.sh" 8 | 9 | here="$(dirname "$0")" 10 | src_root="$(readlink -f "${here}/..")" 11 | cd "${src_root}" 12 | 13 | dir=$1 14 | 15 | # backup toml file before messing with it 16 | cargo_toml="./Cargo.toml" 17 | cp ${cargo_toml} ${cargo_toml}.bak 18 | 19 | # Remove all other members 20 | toml set ${cargo_toml}.bak workspace.members '' > ${cargo_toml} 21 | sed -i'' "s/members.*/members = [\"$dir\"]/" ${cargo_toml} 22 | 23 | # Remove paths from deps 24 | sed -i'' "s/ path = .*, v/ v/" ${cargo_toml} 25 | 26 | # Remove patches 27 | sed -i'' "s/solana-.* path.*}//" ${cargo_toml} 28 | 29 | # Add it back for the one to test 30 | sed -i'' "s/solana-$dir = {/solana-$dir = { path = \"$dir\",/" ${cargo_toml} 31 | 32 | # Run test 33 | set +e 34 | bash ./scripts/check-minimal-versions.sh 35 | status=$? 36 | 37 | # Restore toml file 38 | mv ${cargo_toml}.bak ${cargo_toml} 39 | 40 | exit $status 41 | -------------------------------------------------------------------------------- /transaction-error/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-transaction-error" 3 | description = "Solana TransactionError type" 4 | documentation = "https://docs.rs/solana-transaction-error" 5 | version = "3.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] 20 | serde = ["dep:serde", "dep:serde_derive", "solana-instruction-error/serde"] 21 | 22 | [dependencies] 23 | serde = { workspace = true, optional = true } 24 | serde_derive = { workspace = true, optional = true } 25 | solana-frozen-abi = { workspace = true, optional = true } 26 | solana-frozen-abi-macro = { workspace = true, optional = true } 27 | solana-instruction-error = { workspace = true } 28 | solana-sanitize = { workspace = true } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /cpi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-cpi" 3 | description = "Solana Cross-program Invocation" 4 | documentation = "https://docs.rs/solana-cpi" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | solana-account-info = { workspace = true } 17 | solana-instruction = { workspace = true, features = ["std"] } 18 | solana-program-error = { workspace = true } 19 | solana-pubkey = { workspace = true } 20 | 21 | [target.'cfg(target_os = "solana")'.dependencies] 22 | solana-define-syscall = { workspace = true } 23 | solana-stable-layout = { workspace = true } 24 | 25 | [dev-dependencies] 26 | solana-program-entrypoint = { workspace = true } 27 | solana-pubkey = { workspace = true, features = ["curve25519"] } 28 | solana-sdk-ids = { workspace = true } 29 | solana-system-interface = { workspace = true, features = ["bincode"] } 30 | static_assertions = { workspace = true } 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /poh-config/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-poh-config" 3 | description = "Definitions of Solana's proof of history." 4 | documentation = "https://docs.rs/solana-poh-config" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 19 | serde = ["dep:serde", "dep:serde_derive"] 20 | 21 | [dependencies] 22 | serde = { workspace = true, optional = true } 23 | serde_derive = { workspace = true, optional = true } 24 | solana-frozen-abi = { workspace = true, optional = true, features = [ 25 | "frozen-abi", 26 | ] } 27 | solana-frozen-abi-macro = { workspace = true, optional = true, features = [ 28 | "frozen-abi", 29 | ] } 30 | 31 | [dev-dependencies] 32 | solana-clock = { workspace = true } 33 | static_assertions = { workspace = true } 34 | 35 | [lints] 36 | workspace = true 37 | -------------------------------------------------------------------------------- /program/src/syscalls/mod.rs: -------------------------------------------------------------------------------- 1 | //! Declarations of Solana program syscalls. 2 | //! 3 | //! This module is mostly empty when not compiling for BPF targets. 4 | 5 | #[cfg(target_os = "solana")] 6 | mod definitions; 7 | 8 | #[cfg(target_os = "solana")] 9 | pub use definitions::*; 10 | 11 | /// Maximum CPI instruction data size. 10 KiB was chosen to ensure that CPI 12 | /// instructions are not more limited than transaction instructions if the size 13 | /// of transactions is doubled in the future. 14 | pub const MAX_CPI_INSTRUCTION_DATA_LEN: u64 = 10 * 1024; 15 | 16 | /// Maximum CPI instruction accounts. 255 was chosen to ensure that instruction 17 | /// accounts are always within the maximum instruction account limit for SBF 18 | /// program instructions. 19 | pub const MAX_CPI_INSTRUCTION_ACCOUNTS: u8 = u8::MAX; 20 | 21 | /// Maximum number of account info structs that can be used in a single CPI 22 | /// invocation. A limit on account info structs is effectively the same as 23 | /// limiting the number of unique accounts. 128 was chosen to match the max 24 | /// number of locked accounts per transaction (MAX_TX_ACCOUNT_LOCKS). 25 | pub const MAX_CPI_ACCOUNT_INFOS: usize = 128; 26 | -------------------------------------------------------------------------------- /instruction-error/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-instruction-error" 3 | description = "Solana InstructionError type." 4 | documentation = "https://docs.rs/solana-instruction-error" 5 | version = "2.1.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | frozen-abi = [ 20 | "dep:solana-frozen-abi", 21 | "dep:solana-frozen-abi-macro", 22 | "serde", 23 | ] 24 | num-traits = ["dep:num-traits"] 25 | serde = ["dep:serde", "dep:serde_derive"] 26 | 27 | [dependencies] 28 | num-traits = { workspace = true, optional = true } 29 | serde = { workspace = true, optional = true } 30 | serde_derive = { workspace = true, optional = true } 31 | solana-frozen-abi = { workspace = true, optional = true } 32 | solana-frozen-abi-macro = { workspace = true, optional = true } 33 | solana-program-error = { workspace = true } 34 | 35 | [lints] 36 | workspace = true 37 | -------------------------------------------------------------------------------- /bls-signatures/src/hash.rs: -------------------------------------------------------------------------------- 1 | use {crate::proof_of_possession::POP_DST, blstrs::G2Projective}; 2 | 3 | /// Domain separation tag used for hashing messages to curve points to prevent 4 | /// potential conflicts between different BLS implementations. This is defined 5 | /// as the ciphersuite ID string as recommended in the 6 | /// [standard](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-05#section-4.2.1). 7 | pub const HASH_TO_POINT_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; 8 | 9 | /// Hash a message to a G2 point for signature generation and verification 10 | /// 11 | /// If hashing a payload for a Proof-of-Possession (PoP), use 12 | /// `hash_pop_payload_to_point` instead. 13 | pub fn hash_signature_message_to_point(message: &[u8]) -> G2Projective { 14 | G2Projective::hash_to_curve(message, HASH_TO_POINT_DST, &[]) 15 | } 16 | 17 | /// Hash a message to a G2 point for proof-of-possession generation and verification 18 | /// 19 | /// If hashing a message for a standard BLS signature, use 20 | /// `hash_signature_message_to_point` instead. 21 | pub(crate) fn hash_pop_payload_to_point(payload: &[u8]) -> G2Projective { 22 | G2Projective::hash_to_curve(payload, POP_DST, &[]) 23 | } 24 | -------------------------------------------------------------------------------- /feature-gate-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Runtime features. 2 | //! 3 | //! Runtime features provide a mechanism for features to be simultaneously activated across the 4 | //! network. Since validators may choose when to upgrade, features must remain dormant until a 5 | //! sufficient majority of the network is running a version that would support a given feature. 6 | //! 7 | //! Feature activation is accomplished by: 8 | //! 1. Activation is requested by the feature authority, who issues a transaction to create the 9 | //! feature account. The newly created feature account will have the value of 10 | //! `Feature::default()` 11 | //! 2. When the next epoch is entered the runtime will check for new activation requests and 12 | //! active them. When this occurs, the activation slot is recorded in the feature account 13 | #![cfg_attr(docsrs, feature(doc_cfg))] 14 | 15 | pub mod error; 16 | pub mod instruction; 17 | pub mod state; 18 | 19 | #[cfg(feature = "bincode")] 20 | pub use crate::{ 21 | instruction::{activate, activate_with_lamports}, 22 | state::{create_account, from_account, to_account}, 23 | }; 24 | pub use { 25 | crate::state::Feature, 26 | solana_sdk_ids::feature::{check_id, id, ID}, 27 | }; 28 | -------------------------------------------------------------------------------- /rent/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-rent" 3 | description = "Configuration for Solana network rent." 4 | documentation = "https://docs.rs/solana-rent" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 17 | serde = ["dep:serde", "dep:serde_derive"] 18 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 19 | 20 | [dependencies] 21 | serde = { workspace = true, optional = true } 22 | serde_derive = { workspace = true, optional = true } 23 | solana-frozen-abi = { workspace = true, optional = true } 24 | solana-frozen-abi-macro = { workspace = true, optional = true } 25 | solana-sdk-ids = { workspace = true, optional = true } 26 | solana-sdk-macro = { workspace = true } 27 | solana-sysvar-id = { workspace = true, optional = true } 28 | 29 | [dev-dependencies] 30 | solana-clock = { workspace = true } 31 | static_assertions = { workspace = true } 32 | 33 | [lints] 34 | workspace = true 35 | -------------------------------------------------------------------------------- /example-mocks/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-example-mocks" 3 | description = "Solana mock types for use in examples" 4 | documentation = "https://docs.rs/solana-example-mocks" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["solana-system-interface/bincode"] 19 | 20 | [dependencies] 21 | serde = { workspace = true } 22 | serde_derive = { workspace = true } 23 | solana-address-lookup-table-interface = { workspace = true } 24 | solana-clock = { workspace = true } 25 | solana-hash = { workspace = true } 26 | solana-instruction = { workspace = true } 27 | solana-keccak-hasher = { workspace = true } 28 | solana-message = { workspace = true, features = ["serde"] } 29 | solana-nonce = { workspace = true } 30 | solana-pubkey = { workspace = true, features = ["std"] } 31 | solana-sdk-ids = { workspace = true } 32 | solana-system-interface = { workspace = true } 33 | thiserror = { workspace = true } 34 | -------------------------------------------------------------------------------- /epoch-stake/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! API for retrieving epoch stake information. 2 | //! 3 | //! On-chain programs can use this API to retrieve the total stake for the 4 | //! current epoch or the stake for a specific vote account using the 5 | //! `sol_get_epoch_stake` syscall. 6 | #![cfg_attr(docsrs, feature(doc_cfg))] 7 | #![no_std] 8 | 9 | use solana_pubkey::Pubkey; 10 | 11 | fn get_epoch_stake(var_addr: *const u8) -> u64 { 12 | #[cfg(target_os = "solana")] 13 | { 14 | unsafe { solana_define_syscall::definitions::sol_get_epoch_stake(var_addr) } 15 | } 16 | 17 | #[cfg(not(target_os = "solana"))] 18 | { 19 | core::hint::black_box(var_addr); 20 | 0 21 | } 22 | } 23 | 24 | /// Get the current epoch's total stake. 25 | pub fn get_epoch_total_stake() -> u64 { 26 | get_epoch_stake(core::ptr::null::() as *const u8) 27 | } 28 | 29 | /// Get the current epoch stake for a given vote address. 30 | /// 31 | /// If the provided vote address corresponds to an account that is not a vote 32 | /// account or does not exist, returns `0` for active stake. 33 | pub fn get_epoch_stake_for_vote_account(vote_address: &Pubkey) -> u64 { 34 | get_epoch_stake(vote_address as *const _ as *const u8) 35 | } 36 | -------------------------------------------------------------------------------- /bn254/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-bn254" 3 | description = "Solana BN254" 4 | documentation = "https://docs.rs/solana-bn254" 5 | version = "3.1.2" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | include = ["src/**/*"] 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [dependencies] 19 | bytemuck = { workspace = true, features = ["derive"] } 20 | thiserror = { workspace = true } 21 | 22 | [target.'cfg(not(target_os = "solana"))'.dependencies] 23 | ark-bn254 = { workspace = true } 24 | ark-ec = { workspace = true } 25 | ark-ff = { workspace = true } 26 | ark-serialize = { workspace = true } 27 | 28 | [target.'cfg(target_os = "solana")'.dependencies] 29 | solana-define-syscall = { workspace = true } 30 | 31 | [dev-dependencies] 32 | array-bytes = { workspace = true } 33 | criterion = { workspace = true } 34 | serde = { workspace = true } 35 | serde_derive = { workspace = true } 36 | serde_json = { workspace = true } 37 | 38 | [[bench]] 39 | name = "bn254" 40 | harness = false 41 | 42 | [lints] 43 | workspace = true 44 | -------------------------------------------------------------------------------- /pubkey/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Solana account addresses. 2 | #![no_std] 3 | #![cfg_attr(docsrs, feature(doc_cfg))] 4 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 5 | #![allow(clippy::arithmetic_side_effects)] 6 | 7 | // If target_os = "solana", then this panics so there are no dependencies. 8 | // When target_os != "solana", this should be opt-in so users 9 | // don't need the curve25519 dependency. 10 | #[cfg(any(target_os = "solana", feature = "curve25519"))] 11 | pub use solana_address::bytes_are_curve_point; 12 | #[cfg(target_os = "solana")] 13 | pub use solana_address::syscalls; 14 | pub use solana_address::{ 15 | address as pubkey, declare_deprecated_id, declare_id, 16 | error::{AddressError as PubkeyError, ParseAddressError as ParsePubkeyError}, 17 | Address as Pubkey, ADDRESS_BYTES as PUBKEY_BYTES, MAX_SEEDS, MAX_SEED_LEN, 18 | }; 19 | #[cfg(all(feature = "rand", not(target_os = "solana")))] 20 | pub use solana_address::{ 21 | AddressHasher as PubkeyHasher, AddressHasherBuilder as PubkeyHasherBuilder, 22 | }; 23 | 24 | /// New random `Pubkey` for tests and benchmarks. 25 | #[cfg(all(feature = "rand", not(target_os = "solana")))] 26 | pub fn new_rand() -> Pubkey { 27 | Pubkey::from(rand::random::<[u8; PUBKEY_BYTES]>()) 28 | } 29 | -------------------------------------------------------------------------------- /program/src/bpf_loader.rs: -------------------------------------------------------------------------------- 1 | //! The latest BPF loader native program. 2 | //! 3 | //! The BPF loader is responsible for loading, finalizing, and executing BPF 4 | //! programs. Not all networks may support the latest loader. You can use the 5 | //! command-line tools to check if this version of the loader is supported by 6 | //! requesting the account info for the public key below. 7 | //! 8 | //! The program format may change between loaders, and it is crucial to build 9 | //! your program against the proper entrypoint semantics. All programs being 10 | //! deployed to this BPF loader must build against the latest entrypoint version 11 | //! located in `entrypoint.rs`. 12 | //! 13 | //! Note: Programs built for older loaders must use a matching entrypoint 14 | //! version. An example is [`bpf_loader_deprecated`] which requires 15 | //! [`entrypoint_deprecated`]. 16 | //! 17 | //! The `solana program deploy` CLI command uses the 18 | //! [upgradeable BPF loader][ubpfl]. 19 | //! 20 | //! [`bpf_loader_deprecated`]: crate::bpf_loader_deprecated 21 | //! [`entrypoint_deprecated`]: mod@crate::entrypoint_deprecated 22 | //! [ubpfl]: https://docs.rs/solana-loader-v3-interface/latest/solana_loader_v3_interface/index.html 23 | pub use solana_sdk_ids::bpf_loader::{check_id, id, ID}; 24 | -------------------------------------------------------------------------------- /pubkey/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-pubkey" 3 | description = "Solana account addresses" 4 | documentation = "https://docs.rs/solana-pubkey" 5 | version = "4.0.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | borsh = ["solana-address/borsh"] 20 | bytemuck = ["solana-address/bytemuck"] 21 | curve25519 = ["solana-address/curve25519"] 22 | default = ["std"] 23 | dev-context-only-utils = ["solana-address/dev-context-only-utils"] 24 | frozen-abi = ["solana-address/frozen-abi"] 25 | rand = ["dep:rand", "solana-address/rand"] 26 | serde = ["solana-address/serde"] 27 | sha2 = ["solana-address/sha2"] 28 | std = ["solana-address/atomic", "solana-address/std"] 29 | alloc = ["solana-address/alloc"] 30 | 31 | [dependencies] 32 | rand = { workspace = true, optional = true } 33 | solana-address = { workspace = true, features = [ 34 | "copy", 35 | "decode", 36 | "error", 37 | "sanitize", 38 | "syscalls", 39 | ] } 40 | 41 | [lints] 42 | workspace = true 43 | -------------------------------------------------------------------------------- /offchain-message/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-offchain-message" 3 | description = "Solana offchain message signing" 4 | documentation = "https://docs.rs/solana-offchain-message" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | dev-context-only-utils = ["verify"] 19 | verify = ["dep:solana-pubkey", "solana-signature/verify"] 20 | 21 | [dependencies] 22 | num_enum = { workspace = true } 23 | solana-hash = { workspace = true } 24 | solana-packet = { workspace = true } 25 | solana-pubkey = { workspace = true, optional = true } 26 | solana-sanitize = { workspace = true } 27 | solana-sha256-hasher = { workspace = true, features = ["sha2"] } 28 | solana-signature = { workspace = true } 29 | solana-signer = { workspace = true } 30 | 31 | [dev-dependencies] 32 | solana-hash = { workspace = true, features = ["decode"] } 33 | solana-keypair = { workspace = true } 34 | solana-offchain-message = { path = ".", features = ["dev-context-only-utils"] } 35 | static_assertions = { workspace = true } 36 | -------------------------------------------------------------------------------- /compute-budget-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-compute-budget-interface" 3 | description = "Solana compute budget interface." 4 | documentation = "https://docs.rs/solana-compute-budget-interface" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | borsh = ["dep:borsh"] 19 | dev-context-only-utils = ["borsh"] 20 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] 21 | serde = ["dep:serde", "dep:serde_derive"] 22 | 23 | [dependencies] 24 | borsh = { workspace = true, optional = true } 25 | serde = { workspace = true, optional = true } 26 | serde_derive = { workspace = true, optional = true } 27 | solana-frozen-abi = { workspace = true, features = [ 28 | "frozen-abi", 29 | ], optional = true } 30 | solana-frozen-abi-macro = { workspace = true, features = [ 31 | "frozen-abi", 32 | ], optional = true } 33 | solana-instruction = { workspace = true, features = ["std"] } 34 | solana-sdk-ids = { workspace = true } 35 | 36 | [lints] 37 | workspace = true 38 | -------------------------------------------------------------------------------- /address-lookup-table-interface/src/error.rs: -------------------------------------------------------------------------------- 1 | use core::fmt; 2 | 3 | #[derive(Debug, PartialEq, Eq, Clone)] 4 | pub enum AddressLookupError { 5 | /// Attempted to lookup addresses from a table that does not exist 6 | LookupTableAccountNotFound, 7 | 8 | /// Attempted to lookup addresses from an account owned by the wrong program 9 | InvalidAccountOwner, 10 | 11 | /// Attempted to lookup addresses from an invalid account 12 | InvalidAccountData, 13 | 14 | /// Address lookup contains an invalid index 15 | InvalidLookupIndex, 16 | } 17 | 18 | impl core::error::Error for AddressLookupError {} 19 | 20 | impl fmt::Display for AddressLookupError { 21 | fn fmt(&self, f: &mut ::core::fmt::Formatter) -> fmt::Result { 22 | f.write_str(match self { 23 | Self::LookupTableAccountNotFound => { 24 | "Attempted to lookup addresses from a table that does not exist" 25 | } 26 | Self::InvalidAccountOwner => { 27 | "Attempted to lookup addresses from an account owned by the wrong program" 28 | } 29 | Self::InvalidAccountData => "Attempted to lookup addresses from an invalid account", 30 | Self::InvalidLookupIndex => "Address lookup contains an invalid index", 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /epoch-schedule/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-epoch-schedule" 3 | description = "Configuration for Solana epochs and slots." 4 | documentation = "https://docs.rs/solana-epoch-schedule" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 17 | serde = ["dep:serde", "dep:serde_derive"] 18 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 19 | 20 | [dependencies] 21 | serde = { workspace = true, optional = true } 22 | serde_derive = { workspace = true, optional = true } 23 | solana-frozen-abi = { workspace = true, optional = true } 24 | solana-frozen-abi-macro = { workspace = true, optional = true } 25 | solana-sdk-ids = { workspace = true, optional = true } 26 | solana-sdk-macro = { workspace = true } 27 | solana-sysvar-id = { workspace = true, optional = true } 28 | 29 | [dev-dependencies] 30 | solana-clock = { workspace = true } 31 | solana-epoch-schedule = { path = ".", features = ["sysvar"] } 32 | static_assertions = { workspace = true } 33 | 34 | [lints] 35 | workspace = true 36 | -------------------------------------------------------------------------------- /nonce/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-nonce" 3 | description = "Solana durable transaction nonces." 4 | documentation = "https://docs.rs/solana-nonce" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | dev-context-only-utils = ["serde"] 19 | serde = [ 20 | "dep:serde", 21 | "dep:serde_derive", 22 | "serde/alloc", 23 | "solana-fee-calculator/serde", 24 | "solana-hash/serde", 25 | "solana-pubkey/serde", 26 | ] 27 | 28 | [dependencies] 29 | serde = { workspace = true, optional = true } 30 | serde_derive = { workspace = true, optional = true } 31 | solana-fee-calculator = { workspace = true } 32 | solana-hash = { workspace = true, features = ["copy", "decode"] } 33 | solana-pubkey = { workspace = true, default-features = false } 34 | solana-sha256-hasher = { workspace = true } 35 | 36 | [dev-dependencies] 37 | bincode = { workspace = true } 38 | solana-nonce = { path = ".", features = ["dev-context-only-utils"] } 39 | solana-pubkey = { workspace = true, features = ["std"], default-features = false } 40 | -------------------------------------------------------------------------------- /system-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! The System program interface. 2 | 3 | #![no_std] 4 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 5 | #![cfg_attr(docsrs, feature(doc_cfg))] 6 | 7 | #[cfg(feature = "alloc")] 8 | extern crate alloc; 9 | #[cfg(feature = "std")] 10 | extern crate std; 11 | 12 | pub mod error; 13 | pub mod instruction; 14 | 15 | #[cfg(test)] 16 | static_assertions::const_assert!(MAX_PERMITTED_DATA_LENGTH <= u32::MAX as u64); 17 | /// Maximum permitted size of account data (10 MiB). 18 | /// 19 | // SBF program entrypoint assumes that the max account data length 20 | // will fit inside a u32. If this constant no longer fits in a u32, 21 | // the entrypoint deserialization code in the SDK must be updated. 22 | pub const MAX_PERMITTED_DATA_LENGTH: u64 = 10 * 1024 * 1024; 23 | 24 | #[cfg(test)] 25 | static_assertions::const_assert_eq!(MAX_PERMITTED_DATA_LENGTH, 10_485_760); 26 | /// Maximum permitted size of new allocations per transaction, in bytes. 27 | /// 28 | /// The value was chosen such that at least one max sized account could be created, 29 | /// plus some additional resize allocations. 30 | pub const MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION: i64 = 31 | MAX_PERMITTED_DATA_LENGTH as i64 * 2; 32 | 33 | pub mod program { 34 | solana_address::declare_id!("11111111111111111111111111111111"); 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/sysvar-comment.yml: -------------------------------------------------------------------------------- 1 | name: Sysvar Auto-Comment 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - synchronize 8 | paths: 9 | - 'clock/src/**' 10 | - 'epoch-rewards/src/**' 11 | - 'epoch-schedule/src/**' 12 | - 'fee-calculator/src/**' 13 | - 'last-restart-slot/src/**' 14 | - 'rent/src/**' 15 | - 'slot-hashes/src/**' 16 | - 'slot-history/src/**' 17 | - 'sysvar/src/**' 18 | - 'sysvar-id/src/**' 19 | 20 | jobs: 21 | comment: 22 | runs-on: ubuntu-latest 23 | permissions: 24 | contents: read 25 | pull-requests: write 26 | steps: 27 | - name: Git Checkout 28 | uses: actions/checkout@v4 29 | 30 | - name: PR Comment 31 | run: 32 | gh pr comment $PRNUM --body "$COMMENT" 33 | env: 34 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | GH_REPO: ${{ github.repository }} 36 | PRNUM: ${{ github.event.pull_request.number }} 37 | COMMENT: "If this PR represents a change to the sysvar layout, please 38 | open a follow-up PR to update the JavaScript client `@solana/sysvars` 39 | ([example](https://github.com/anza-xyz/kit/pull/375)) 40 | 41 | Thank you for keeping the JavaScript clients in sync with the Rust 42 | clients." 43 | -------------------------------------------------------------------------------- /keypair/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-keypair" 3 | description = "Concrete implementation of a Solana `Signer`." 4 | documentation = "https://docs.rs/solana-keypair" 5 | version = "3.1.0" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | seed-derivable = [ 20 | "dep:solana-derivation-path", 21 | "dep:solana-seed-derivable", 22 | "dep:ed25519-dalek-bip32", 23 | ] 24 | 25 | [dependencies] 26 | ed25519-dalek = { workspace = true, features = ["rand_core"] } 27 | ed25519-dalek-bip32 = { workspace = true, optional = true } 28 | five8 = { workspace = true } 29 | rand = { workspace = true } 30 | solana-address = { workspace = true, features = ["decode"] } 31 | solana-derivation-path = { workspace = true, optional = true } 32 | solana-seed-derivable = { workspace = true, optional = true } 33 | solana-seed-phrase = { workspace = true } 34 | solana-signature = { workspace = true, features = ["std", "verify"] } 35 | solana-signer = { workspace = true } 36 | 37 | [dev-dependencies] 38 | serde_json = { workspace = true } 39 | static_assertions = { workspace = true } 40 | tiny-bip39 = { workspace = true } 41 | -------------------------------------------------------------------------------- /loader-v3-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | //! An upgradeable BPF loader native program. 4 | //! 5 | //! The upgradeable BPF loader is responsible for deploying, upgrading, and 6 | //! executing BPF programs. The upgradeable loader allows a program's authority 7 | //! to update the program at any time. This ability breaks the "code is law" 8 | //! contract that once a program is on-chain it is immutable. Because of this, 9 | //! care should be taken before executing upgradeable programs which still have 10 | //! a functioning authority. For more information refer to the 11 | //! [`instruction`] module. 12 | //! 13 | //! The `solana program deploy` CLI command uses the 14 | //! upgradeable BPF loader. Calling `solana program deploy --final` deploys a 15 | //! program that cannot be upgraded, but it does so by revoking the authority to 16 | //! upgrade, not by using the non-upgradeable loader. 17 | //! 18 | //! [`instruction`]: crate::instruction 19 | 20 | use solana_pubkey::Pubkey; 21 | 22 | pub mod instruction; 23 | pub mod state; 24 | 25 | /// Returns the program data address for a program ID 26 | pub fn get_program_data_address(program_address: &Pubkey) -> Pubkey { 27 | Pubkey::find_program_address( 28 | &[program_address.as_ref()], 29 | &solana_sdk_ids::bpf_loader_upgradeable::id(), 30 | ) 31 | .0 32 | } 33 | -------------------------------------------------------------------------------- /instructions-sysvar/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-instructions-sysvar" 3 | description = "Type for instruction introspection during execution of Solana programs." 4 | documentation = "https://docs.rs/solana-instructions-sysvar" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | dev-context-only-utils = ["dep:qualifier_attr"] 19 | 20 | [dependencies] 21 | qualifier_attr = { workspace = true, optional = true } 22 | solana-account-info = { workspace = true } 23 | solana-instruction = { workspace = true, default-features = false, features = ["std"] } 24 | solana-instruction-error = { workspace = true } 25 | solana-program-error = { workspace = true } 26 | solana-pubkey = { workspace = true, default-features = false } 27 | solana-sanitize = { workspace = true } 28 | solana-sdk-ids = { workspace = true } 29 | solana-serialize-utils = { workspace = true } 30 | solana-sysvar-id = { workspace = true } 31 | 32 | [target.'cfg(not(target_os = "solana"))'.dependencies] 33 | bitflags = { workspace = true } 34 | 35 | [dev-dependencies] 36 | solana-address = { workspace = true, features = ["atomic"] } 37 | 38 | [lints] 39 | workspace = true 40 | -------------------------------------------------------------------------------- /sdk-wasm-js/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-sdk-wasm-js" 3 | description = "Solana SDK Wasm JS" 4 | documentation = "https://docs.rs/solana-sdk-wasm-js" 5 | version = "1.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["wasm32-unknown-unknown"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [lib] 18 | crate-type = ["cdylib", "rlib"] 19 | 20 | [dependencies] 21 | bincode = { workspace = true } 22 | solana-address = { workspace = true, features = ["curve25519", "sha2", "std"] } 23 | solana-hash = { workspace = true } 24 | solana-instruction = { workspace = true, features = ["std"] } 25 | solana-keypair = { workspace = true } 26 | solana-message = { workspace = true } 27 | solana-packet = { workspace = true } 28 | solana-signature = { workspace = true } 29 | solana-signer = { workspace = true } 30 | solana-transaction = { workspace = true, features = ["bincode", "verify"] } 31 | 32 | [target.'cfg(target_arch = "wasm32")'.dependencies] 33 | console_error_panic_hook = { workspace = true } 34 | console_log = { workspace = true } 35 | getrandom = { workspace = true, features = ["wasm_js"] } 36 | js-sys = { workspace = true } 37 | log = { workspace = true } 38 | wasm-bindgen = { workspace = true } 39 | 40 | [lints] 41 | workspace = true 42 | -------------------------------------------------------------------------------- /frozen-abi/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(incomplete_features)] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #![cfg_attr(feature = "frozen-abi", feature(specialization))] 4 | // Activate some of the Rust 2024 lints to make the future migration easier. 5 | #![warn(if_let_rescope)] 6 | #![warn(keyword_idents_2024)] 7 | #![warn(rust_2024_incompatible_pat)] 8 | #![warn(tail_expr_drop_order)] 9 | #![warn(unsafe_attr_outside_unsafe)] 10 | #![warn(unsafe_op_in_unsafe_fn)] 11 | 12 | // Allows macro expansion of `use ::solana_frozen_abi::*` to work within this crate 13 | extern crate self as solana_frozen_abi; 14 | 15 | #[cfg(feature = "frozen-abi")] 16 | pub mod abi_digester; 17 | #[cfg(feature = "frozen-abi")] 18 | pub mod abi_example; 19 | #[cfg(feature = "frozen-abi")] 20 | pub mod hash; 21 | 22 | #[cfg(all(feature = "frozen-abi", not(target_os = "solana")))] 23 | pub mod stable_abi; 24 | 25 | #[cfg(feature = "frozen-abi")] 26 | #[macro_use] 27 | extern crate solana_frozen_abi_macro; 28 | 29 | #[cfg(all(feature = "frozen-abi", not(target_os = "solana")))] 30 | pub use {bincode, rand, rand_chacha}; 31 | 32 | // Not public API. Previously referenced by macro-generated code. Remove the 33 | // `log` dependency from Cargo.toml when this is cleaned up in the next major 34 | // version bump 35 | #[deprecated(since = "3.0.1", note = "Please use the `log` crate directly instead")] 36 | #[doc(hidden)] 37 | pub mod __private { 38 | #[doc(hidden)] 39 | pub use log; 40 | } 41 | -------------------------------------------------------------------------------- /epoch-rewards/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-epoch-rewards" 3 | description = "Solana epoch rewards sysvar." 4 | documentation = "https://docs.rs/solana-epoch-rewards" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | frozen-abi = [ 19 | "dep:solana-frozen-abi", 20 | "dep:solana-frozen-abi-macro", 21 | "solana-hash/frozen-abi", 22 | "std", 23 | ] 24 | serde = ["dep:serde", "dep:serde_derive", "serde/alloc", "solana-hash/serde"] 25 | std = ["serde?/std"] 26 | sysvar = ["dep:solana-sdk-ids", "dep:solana-sysvar-id"] 27 | 28 | [dependencies] 29 | serde = { workspace = true, optional = true } 30 | serde_derive = { workspace = true, optional = true } 31 | solana-frozen-abi = { workspace = true, optional = true } 32 | solana-frozen-abi-macro = { workspace = true, optional = true } 33 | solana-hash = { workspace = true, features = ["decode"] } 34 | solana-sdk-ids = { workspace = true, optional = true } 35 | solana-sdk-macro = { workspace = true } 36 | solana-sysvar-id = { workspace = true, optional = true } 37 | 38 | [dev-dependencies] 39 | solana-epoch-rewards = { path = ".", features = ["sysvar"] } 40 | 41 | [lints] 42 | workspace = true 43 | -------------------------------------------------------------------------------- /bls-signatures/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 4 | 5 | extern crate alloc; 6 | 7 | #[cfg(feature = "std")] 8 | extern crate std; 9 | #[cfg(not(target_os = "solana"))] 10 | pub use crate::{ 11 | error::BlsError, 12 | keypair::Keypair, 13 | proof_of_possession::{ 14 | AsProofOfPossessionProjective, ProofOfPossessionProjective, VerifiableProofOfPossession, 15 | }, 16 | pubkey::{AsPubkeyProjective, PubkeyProjective, VerifiablePubkey}, 17 | secret_key::{SecretKey, BLS_SECRET_KEY_SIZE}, 18 | signature::{AsSignatureProjective, SignatureProjective, VerifiableSignature}, 19 | }; 20 | pub use crate::{ 21 | proof_of_possession::{ 22 | ProofOfPossession, ProofOfPossessionCompressed, BLS_PROOF_OF_POSSESSION_AFFINE_SIZE, 23 | BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, 24 | }, 25 | pubkey::{ 26 | Pubkey, PubkeyCompressed, BLS_PUBLIC_KEY_AFFINE_SIZE, BLS_PUBLIC_KEY_COMPRESSED_SIZE, 27 | }, 28 | signature::{ 29 | Signature, SignatureCompressed, BLS_SIGNATURE_AFFINE_SIZE, BLS_SIGNATURE_COMPRESSED_SIZE, 30 | }, 31 | }; 32 | 33 | pub mod error; 34 | #[cfg(not(target_os = "solana"))] 35 | pub mod keypair; 36 | #[macro_use] 37 | pub(crate) mod macros; 38 | #[cfg(not(target_os = "solana"))] 39 | pub mod hash; 40 | pub mod proof_of_possession; 41 | pub mod pubkey; 42 | #[cfg(not(target_os = "solana"))] 43 | pub mod secret_key; 44 | pub mod signature; 45 | -------------------------------------------------------------------------------- /secp256k1-recover/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-secp256k1-recover" 3 | description = "Solana SECP256K1 Recover" 4 | documentation = "https://docs.rs/solana-secp256k1-recover" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [features] 16 | borsh = ["dep:borsh"] 17 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 18 | 19 | [dependencies] 20 | borsh = { workspace = true, optional = true } 21 | solana-frozen-abi = { workspace = true, optional = true, features = [ 22 | "frozen-abi", 23 | ] } 24 | solana-frozen-abi-macro = { workspace = true, optional = true, features = [ 25 | "frozen-abi", 26 | ] } 27 | thiserror = { workspace = true } 28 | 29 | [target.'cfg(any(target_os = "solana", target_arch = "bpf"))'.dependencies] 30 | solana-define-syscall = { workspace = true } 31 | 32 | [target.'cfg(not(any(target_os = "solana", target_arch = "bpf")))'.dependencies] 33 | k256 = { workspace = true } 34 | 35 | [dev-dependencies] 36 | anyhow = { workspace = true } 37 | borsh = { workspace = true } 38 | rand = "0.8" # k256 still uses rand_core v0.6 39 | solana-program = { path = "../program" } 40 | 41 | [target.'cfg(not(target_os = "solana"))'.dev-dependencies] 42 | k256 = { workspace = true, features = ["ecdsa-core"] } 43 | 44 | [lints] 45 | workspace = true 46 | -------------------------------------------------------------------------------- /sdk-wasm-js/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! solana-program Javascript interface 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #![cfg(target_arch = "wasm32")] 4 | 5 | use { 6 | log::Level, 7 | wasm_bindgen::prelude::{wasm_bindgen, JsValue}, 8 | }; 9 | 10 | pub mod address; 11 | pub mod hash; 12 | pub mod instruction; 13 | pub mod keypair; 14 | pub mod message; 15 | pub mod transaction; 16 | 17 | /// Initialize Javascript logging and panic handler 18 | #[wasm_bindgen] 19 | pub fn solana_program_init() { 20 | use std::sync::Once; 21 | static INIT: Once = Once::new(); 22 | 23 | INIT.call_once(|| { 24 | std::panic::set_hook(Box::new(console_error_panic_hook::hook)); 25 | console_log::init_with_level(Level::Info).unwrap(); 26 | }); 27 | } 28 | 29 | pub fn display_to_jsvalue(display: T) -> JsValue { 30 | display.to_string().into() 31 | } 32 | 33 | /// Simple macro for implementing conversion functions between wrapper types and 34 | /// wrapped types. 35 | mod conversion { 36 | macro_rules! impl_inner_conversion { 37 | ($Wrapper:ty, $Inner:ty) => { 38 | impl From<$Inner> for $Wrapper { 39 | fn from(inner: $Inner) -> Self { 40 | Self { inner } 41 | } 42 | } 43 | impl std::ops::Deref for $Wrapper { 44 | type Target = $Inner; 45 | fn deref(&self) -> &Self::Target { 46 | &self.inner 47 | } 48 | } 49 | }; 50 | } 51 | pub(crate) use impl_inner_conversion; 52 | } 53 | -------------------------------------------------------------------------------- /scripts/publish-rust.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | base="$(dirname "${BASH_SOURCE[0]}")" 5 | # pacify shellcheck: cannot follow dynamic path 6 | # shellcheck disable=SC1090,SC1091 7 | source "$base/read-cargo-variable.sh" 8 | cd "$base/.." 9 | 10 | if [[ -z $1 ]]; then 11 | echo 'A package manifest path — e.g. "program" — must be provided.' 12 | exit 1 13 | fi 14 | PACKAGE_PATH=$1 15 | if [[ -z $2 ]]; then 16 | echo 'A version level — e.g. "patch" — must be provided.' 17 | exit 1 18 | fi 19 | LEVEL=$2 20 | DEPENDENT_VERSION=$3 21 | DRY_RUN=$4 22 | 23 | # Go to the directory 24 | cd "${PACKAGE_PATH}" 25 | 26 | # Get the old version, used with git-cliff 27 | old_version=$(readCargoVariable version "Cargo.toml") 28 | package_name=$(readCargoVariable name "Cargo.toml") 29 | tag_name="${package_name//solana-/}" 30 | 31 | # Publish the new version, commit the repo change, tag it, and push it all. 32 | if [[ -n ${DRY_RUN} ]]; then 33 | cargo release "${LEVEL}" 34 | else 35 | cargo release "${LEVEL}" --tag-name "${tag_name}@v{{version}}" --no-confirm --execute --dependent-version "${DEPENDENT_VERSION}" 36 | fi 37 | 38 | # Stop here if this is a dry run. 39 | if [[ -n $DRY_RUN ]]; then 40 | exit 0 41 | fi 42 | 43 | # Get the new version. 44 | new_version=$(readCargoVariable version "Cargo.toml") 45 | new_git_tag="${tag_name}@v${new_version}" 46 | old_git_tag="${tag_name}@v${old_version}" 47 | 48 | # Expose the new version to CI if needed. 49 | if [[ -n $CI ]]; then 50 | echo "new_git_tag=${new_git_tag}" >> "$GITHUB_OUTPUT" 51 | echo "old_git_tag=${old_git_tag}" >> "$GITHUB_OUTPUT" 52 | fi 53 | -------------------------------------------------------------------------------- /reward-info/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #[cfg(feature = "serde")] 4 | use serde_derive::{Deserialize, Serialize}; 5 | #[cfg(feature = "frozen-abi")] 6 | use solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample}; 7 | use std::fmt; 8 | 9 | #[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] 10 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] 11 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] 12 | pub enum RewardType { 13 | Fee, 14 | Rent, 15 | Staking, 16 | Voting, 17 | } 18 | 19 | impl fmt::Display for RewardType { 20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 21 | write!( 22 | f, 23 | "{}", 24 | match self { 25 | RewardType::Fee => "fee", 26 | RewardType::Rent => "rent", 27 | RewardType::Staking => "staking", 28 | RewardType::Voting => "voting", 29 | } 30 | ) 31 | } 32 | } 33 | 34 | #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] 35 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] 36 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] 37 | pub struct RewardInfo { 38 | pub reward_type: RewardType, 39 | /// Reward amount 40 | pub lamports: i64, 41 | /// Account balance in lamports after `lamports` was applied 42 | pub post_balance: u64, 43 | /// Vote account commission when the reward was credited, only present for voting and staking rewards 44 | pub commission: Option, 45 | } 46 | -------------------------------------------------------------------------------- /feature-gate-interface/src/instruction.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "bincode")] 2 | use { 3 | crate::state::Feature, 4 | solana_instruction::{AccountMeta, Instruction}, 5 | solana_pubkey::Pubkey, 6 | solana_rent::Rent, 7 | solana_sdk_ids::{feature::id, incinerator, system_program}, 8 | solana_system_interface::instruction as system_instruction, 9 | }; 10 | 11 | #[cfg(feature = "bincode")] 12 | /// Activate a feature 13 | pub fn activate(feature_id: &Pubkey, funding_address: &Pubkey, rent: &Rent) -> Vec { 14 | activate_with_lamports( 15 | feature_id, 16 | funding_address, 17 | rent.minimum_balance(Feature::size_of()), 18 | ) 19 | } 20 | 21 | #[cfg(feature = "bincode")] 22 | pub fn activate_with_lamports( 23 | feature_id: &Pubkey, 24 | funding_address: &Pubkey, 25 | lamports: u64, 26 | ) -> Vec { 27 | vec![ 28 | system_instruction::transfer(funding_address, feature_id, lamports), 29 | system_instruction::allocate(feature_id, Feature::size_of() as u64), 30 | system_instruction::assign(feature_id, &id()), 31 | ] 32 | } 33 | 34 | /// Creates a 'RevokePendingActivation' instruction. 35 | #[cfg(feature = "bincode")] 36 | pub fn revoke_pending_activation(feature_id: &Pubkey) -> Instruction { 37 | let accounts = vec![ 38 | AccountMeta::new(*feature_id, true), 39 | AccountMeta::new(incinerator::id(), false), 40 | AccountMeta::new_readonly(system_program::id(), false), 41 | ]; 42 | 43 | Instruction { 44 | program_id: crate::id(), 45 | accounts, 46 | data: vec![0], 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sanitize/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A trait for sanitizing values and members of over the wire messages. 2 | 3 | #![no_std] 4 | #![cfg_attr(docsrs, feature(doc_cfg))] 5 | 6 | use core::{error::Error, fmt}; 7 | 8 | #[derive(PartialEq, Debug, Eq, Clone)] 9 | pub enum SanitizeError { 10 | IndexOutOfBounds, 11 | ValueOutOfBounds, 12 | InvalidValue, 13 | } 14 | 15 | impl Error for SanitizeError {} 16 | 17 | impl fmt::Display for SanitizeError { 18 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 19 | match self { 20 | SanitizeError::IndexOutOfBounds => f.write_str("index out of bounds"), 21 | SanitizeError::ValueOutOfBounds => f.write_str("value out of bounds"), 22 | SanitizeError::InvalidValue => f.write_str("invalid value"), 23 | } 24 | } 25 | } 26 | 27 | /// A trait for sanitizing values and members of over-the-wire messages. 28 | /// 29 | /// Implementation should recursively descend through the data structure and 30 | /// sanitize all struct members and enum clauses. Sanitize excludes signature- 31 | /// verification checks, those are handled by another pass. Sanitize checks 32 | /// should include but are not limited to: 33 | /// 34 | /// - All index values are in range. 35 | /// - All values are within their static max/min bounds. 36 | pub trait Sanitize { 37 | fn sanitize(&self) -> Result<(), SanitizeError> { 38 | Ok(()) 39 | } 40 | } 41 | 42 | impl Sanitize for [T] { 43 | fn sanitize(&self) -> Result<(), SanitizeError> { 44 | for x in self.iter() { 45 | x.sanitize()?; 46 | } 47 | Ok(()) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sdk-wasm-js-tests/tests/transaction.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { 3 | solana_program_init, 4 | Address, 5 | Keypair, 6 | Hash, 7 | MyProgramInstruction, 8 | Transaction, 9 | } from "crate"; 10 | solana_program_init(); 11 | 12 | describe("Transaction", function () { 13 | it("Instruction", () => { 14 | const payer = Keypair.fromBytes( 15 | new Uint8Array([ 16 | 241, 230, 222, 64, 184, 48, 232, 92, 156, 210, 229, 183, 154, 251, 5, 17 | 227, 98, 184, 34, 234, 39, 106, 62, 210, 166, 187, 31, 44, 40, 96, 24, 18 | 51, 252, 28, 2, 120, 234, 212, 139, 111, 96, 8, 168, 204, 34, 72, 199, 19 | 205, 117, 165, 82, 51, 32, 93, 211, 36, 239, 245, 139, 218, 99, 211, 20 | 207, 177, 21 | ]) 22 | ); 23 | 24 | const programId = new Address("11111111111111111111111111111111"); 25 | const recentBlockhash = new Hash( 26 | "EETubP5AKHgjPAhzPAFcb8BAY1hMH639CWCFTqi3hq1k" 27 | ); 28 | 29 | let instructions = []; 30 | let instruction = new MyProgramInstruction(programId); 31 | instructions.push(instruction); 32 | 33 | let transaction = new Transaction(instructions, payer.pubkey()); 34 | transaction.partialSign(payer, recentBlockhash); 35 | expect(transaction.isSigned()).to.be.true; 36 | transaction.verify(); 37 | 38 | expect(Buffer.from(transaction.toBytes()).toString("base64")).to.equal( 39 | "AfvLzMtWBl2MvGFOE6rPZ6gjzKv7eVlNXF0wO4VDxjFXZx0AA/x05cmRHJZR8InwR4lBEwVsHSVa/uBwYSh0dQEBAAEC/BwCeOrUi29gCKjMIkjHzXWlUjMgXdMk7/WL2mPTz7EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMSa53YDeCBU8Xqd7OpDtETroO2xLG8dMcbg5KhL8FLrAQEAAA==" 40 | ); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /instruction/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-instruction" 3 | description = "Types for directing the execution of Solana programs." 4 | documentation = "https://docs.rs/solana-instruction" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:bincode", "dep:serde"] 19 | borsh = ["dep:borsh"] 20 | default = ["std"] 21 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde", "std"] 22 | serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] 23 | std = ["serde?/std", "borsh?/std"] 24 | syscalls = ["std"] 25 | 26 | [dependencies] 27 | bincode = { workspace = true, optional = true } 28 | borsh = { workspace = true, optional = true } 29 | serde = { workspace = true, optional = true } 30 | serde_derive = { workspace = true, optional = true } 31 | solana-frozen-abi = { workspace = true, optional = true } 32 | solana-frozen-abi-macro = { workspace = true, optional = true } 33 | solana-instruction-error = { workspace = true, features = ["num-traits"] } 34 | solana-pubkey = { workspace = true, default-features = false } 35 | 36 | [target.'cfg(target_os = "solana")'.dependencies] 37 | solana-define-syscall = { workspace = true } 38 | 39 | [dev-dependencies] 40 | solana-instruction = { path = ".", features = ["borsh"] } 41 | solana-pubkey = { workspace = true, features = ["std"] } 42 | 43 | [lints] 44 | workspace = true 45 | -------------------------------------------------------------------------------- /packet/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-packet" 3 | description = "The definition of a Solana network packet." 4 | documentation = "https://docs.rs/solana-packet" 5 | version = "4.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:bincode", "serde"] 19 | dev-context-only-utils = ["bincode"] 20 | serde = [ 21 | "bitflags/serde", 22 | "dep:cfg_eval", 23 | "dep:serde", 24 | "dep:serde_derive", 25 | "dep:serde_with", 26 | "solana-pubkey/serde", 27 | ] 28 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] 29 | 30 | [dependencies] 31 | bincode = { workspace = true, optional = true } 32 | bitflags = { workspace = true } 33 | cfg_eval = { workspace = true, optional = true } 34 | serde = { workspace = true, optional = true } 35 | serde_derive = { workspace = true, optional = true } 36 | serde_with = { workspace = true, optional = true, features = ["macros"] } 37 | solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } 38 | solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } 39 | solana-pubkey = { workspace = true } 40 | 41 | [dev-dependencies] 42 | solana-packet = { path = ".", features = ["dev-context-only-utils"] } 43 | solana-pubkey = { workspace = true, features = ["std"] } 44 | static_assertions = { workspace = true } 45 | 46 | [lints] 47 | workspace = true 48 | -------------------------------------------------------------------------------- /scripts/check-nits.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | # Logging hygiene: Please don't print from --lib, use the `log` crate instead 9 | declare prints=( 10 | 'print!' 11 | 'println!' 12 | 'eprint!' 13 | 'eprintln!' 14 | 'dbg!' 15 | ) 16 | 17 | # Parts of the tree that are expected to be print free 18 | declare print_free_tree=( 19 | ':**.rs' 20 | ':^address/src/hasher.rs' 21 | ':^address/src/lib.rs' 22 | ':^frozen-abi/src/*.rs' 23 | ':^frozen-abi-macro/src/lib.rs' 24 | ':^msg/src/lib.rs' 25 | ':^program-log/src/logger.rs' 26 | ':^program-option/src/lib.rs' 27 | ':^sysvar/src/program_stubs.rs' 28 | ':^**bin**.rs' 29 | ':^**bench**.rs' 30 | ':^**test**.rs' 31 | ':^**/build.rs' 32 | ) 33 | 34 | if git --no-pager grep -n "${prints[@]/#/-e}" -- "${print_free_tree[@]}"; then 35 | exit 1 36 | fi 37 | 38 | # Github Issues should be used to track outstanding work items instead of 39 | # marking up the code 40 | # 41 | # Ref: https://github.com/solana-labs/solana/issues/6474 42 | # 43 | # shellcheck disable=1001 44 | declare useGithubIssueInsteadOf=( 45 | X\XX 46 | T\BD 47 | F\IXME 48 | #T\ODO # TODO: Disable TODOs once all other TODOs are purged 49 | ) 50 | 51 | if git --no-pager grep -n --max-depth=0 "${useGithubIssueInsteadOf[@]/#/-e }" -- '*.rs' '*.sh' '*.md'; then 52 | exit 1 53 | fi 54 | 55 | # TODO: Remove this `git grep` once TODOs are banned above 56 | # (this command is only used to highlight the current offenders) 57 | git --no-pager grep -n --max-depth=0 "-e TODO" -- '*.rs' '*.sh' '*.md' || true 58 | # END TODO 59 | -------------------------------------------------------------------------------- /message/src/versions/sanitized.rs: -------------------------------------------------------------------------------- 1 | use { 2 | super::VersionedMessage, crate::compiled_instruction::CompiledInstruction, 3 | solana_address::Address, solana_sanitize::SanitizeError, 4 | }; 5 | 6 | /// Wraps a sanitized `VersionedMessage` to provide a safe API 7 | #[derive(Clone, Debug, PartialEq, Eq)] 8 | pub struct SanitizedVersionedMessage { 9 | pub message: VersionedMessage, 10 | } 11 | 12 | impl TryFrom for SanitizedVersionedMessage { 13 | type Error = SanitizeError; 14 | fn try_from(message: VersionedMessage) -> Result { 15 | Self::try_new(message) 16 | } 17 | } 18 | 19 | impl SanitizedVersionedMessage { 20 | pub fn try_new(message: VersionedMessage) -> Result { 21 | message.sanitize()?; 22 | Ok(Self { message }) 23 | } 24 | 25 | /// Program instructions that will be executed in sequence and committed in 26 | /// one atomic transaction if all succeed. 27 | pub fn instructions(&self) -> &[CompiledInstruction] { 28 | self.message.instructions() 29 | } 30 | 31 | /// Program instructions iterator which includes each instruction's program 32 | /// id. 33 | pub fn program_instructions_iter( 34 | &self, 35 | ) -> impl Iterator + Clone { 36 | self.message.instructions().iter().map(move |ix| { 37 | ( 38 | self.message 39 | .static_account_keys() 40 | .get(usize::from(ix.program_id_index)) 41 | .expect("program id index is sanitized"), 42 | ix, 43 | ) 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sdk-wasm-js/src/keypair.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::address::Address, js_sys::Uint8Array, solana_keypair::KEYPAIR_LENGTH, 3 | solana_signer::Signer, wasm_bindgen::prelude::*, 4 | }; 5 | 6 | #[wasm_bindgen] 7 | #[derive(Debug)] 8 | pub struct Keypair { 9 | pub(crate) inner: solana_keypair::Keypair, 10 | } 11 | 12 | crate::conversion::impl_inner_conversion!(Keypair, solana_keypair::Keypair); 13 | 14 | #[allow(non_snake_case)] 15 | #[wasm_bindgen] 16 | impl Keypair { 17 | /// Create a new `Keypair ` 18 | #[wasm_bindgen(constructor)] 19 | pub fn constructor() -> Self { 20 | solana_keypair::Keypair::new().into() 21 | } 22 | 23 | /// Convert a `Keypair` to a `Uint8Array` 24 | pub fn toBytes(&self) -> Box<[u8]> { 25 | self.inner.to_bytes().into() 26 | } 27 | 28 | /// Recover a `Keypair` from a `Uint8Array` 29 | pub fn fromBytes(uint8_array: Uint8Array) -> Result { 30 | if uint8_array.length() as usize != KEYPAIR_LENGTH { 31 | return Err(std::format!( 32 | "Invalid length for Keypair bytes: expected {}, got {}", 33 | KEYPAIR_LENGTH, 34 | uint8_array.length() 35 | ) 36 | .into()); 37 | } 38 | let mut buf = [0u8; KEYPAIR_LENGTH]; 39 | uint8_array.copy_to(&mut buf); 40 | 41 | solana_keypair::Keypair::try_from(buf.as_ref()) 42 | .map(Into::into) 43 | .map_err(|e| e.to_string().into()) 44 | } 45 | 46 | /// Return the `Address` for this `Keypair` 47 | #[wasm_bindgen(js_name = pubkey)] 48 | pub fn js_pubkey(&self) -> Address { 49 | self.inner.pubkey().into() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /loader-v3-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-loader-v3-interface" 3 | description = "Solana loader V3 interface." 4 | documentation = "https://docs.rs/solana-loader-v3-interface" 5 | version = "6.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] 19 | dev-context-only-utils = ["bincode"] 20 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] 21 | serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] 22 | 23 | [dependencies] 24 | serde = { workspace = true, optional = true } 25 | serde_bytes = { workspace = true, optional = true } 26 | serde_derive = { workspace = true, optional = true } 27 | solana-frozen-abi = { workspace = true, features = [ 28 | "frozen-abi", 29 | ], optional = true } 30 | solana-frozen-abi-macro = { workspace = true, features = [ 31 | "frozen-abi", 32 | ], optional = true } 33 | solana-instruction = { workspace = true, features = ["std"] } 34 | solana-pubkey = { workspace = true, features = ["curve25519"] } 35 | solana-sdk-ids = { workspace = true } 36 | solana-system-interface = { workspace = true, features = ["bincode"], optional = true } 37 | 38 | [dev-dependencies] 39 | bincode = { workspace = true } 40 | solana-loader-v3-interface = { path = ".", features = ["dev-context-only-utils"] } 41 | 42 | [lints] 43 | workspace = true 44 | -------------------------------------------------------------------------------- /loader-v4-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-loader-v4-interface" 3 | description = "Solana loader V4 interface." 4 | documentation = "https://docs.rs/solana-loader-v4-interface" 5 | version = "3.1.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:solana-system-interface", "serde", "solana-instruction/bincode"] 19 | dev-context-only-utils = ["bincode"] 20 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "serde"] 21 | serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive", "solana-pubkey/serde"] 22 | 23 | [dependencies] 24 | serde = { workspace = true, optional = true } 25 | serde_bytes = { workspace = true, optional = true } 26 | serde_derive = { workspace = true, optional = true } 27 | solana-frozen-abi = { workspace = true, features = [ 28 | "frozen-abi", 29 | ], optional = true } 30 | solana-frozen-abi-macro = { workspace = true, features = [ 31 | "frozen-abi", 32 | ], optional = true } 33 | solana-instruction = { workspace = true, features = ["std"] } 34 | solana-pubkey = { workspace = true } 35 | solana-sdk-ids = { workspace = true } 36 | solana-system-interface = { workspace = true, features = ["bincode"], optional = true } 37 | 38 | [dev-dependencies] 39 | memoffset = { workspace = true } 40 | solana-loader-v4-interface = { path = ".", features = ["dev-context-only-utils"] } 41 | solana-pubkey = { workspace = true, features = ["std"] } 42 | 43 | [lints] 44 | workspace = true 45 | -------------------------------------------------------------------------------- /program-log/src/wrapper.rs: -------------------------------------------------------------------------------- 1 | //! Logging wrapper for Solana syscalls. 2 | 3 | #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] 4 | use core::hint::black_box; 5 | #[cfg(any(target_os = "solana", target_arch = "bpf"))] 6 | use solana_define_syscall::definitions::{ 7 | sol_log_, sol_log_64_, sol_log_compute_units_, sol_log_data, 8 | }; 9 | 10 | /// Print a string to the log. 11 | #[inline(always)] 12 | pub fn log(message: &str) { 13 | #[cfg(any(target_os = "solana", target_arch = "bpf"))] 14 | unsafe { 15 | sol_log_(message.as_ptr(), message.len() as u64); 16 | } 17 | 18 | #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] 19 | black_box(message); 20 | } 21 | 22 | /// Print 64-bit values represented as hexadecimal to the log. 23 | #[inline(always)] 24 | pub fn log_64(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64) { 25 | #[cfg(any(target_os = "solana", target_arch = "bpf"))] 26 | unsafe { 27 | sol_log_64_(arg1, arg2, arg3, arg4, arg5); 28 | } 29 | 30 | #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] 31 | black_box((arg1, arg2, arg3, arg4, arg5)); 32 | } 33 | 34 | /// Print some slices as `base64`. 35 | #[inline(always)] 36 | pub fn log_data(data: &[&[u8]]) { 37 | #[cfg(any(target_os = "solana", target_arch = "bpf"))] 38 | unsafe { 39 | sol_log_data(data as *const _ as *const u8, data.len() as u64) 40 | }; 41 | 42 | #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] 43 | black_box(data); 44 | } 45 | 46 | /// Print the remaining compute units available to the program. 47 | #[inline] 48 | pub fn log_compute_units() { 49 | #[cfg(any(target_os = "solana", target_arch = "bpf"))] 50 | unsafe { 51 | sol_log_compute_units_(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /transaction/src/simple_vote_transaction_checker.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::versioned::sanitized::SanitizedVersionedTransaction, solana_address::Address, 3 | solana_message::VersionedMessage, solana_signature::Signature, 4 | }; 5 | 6 | /// Simple vote transaction meets these conditions: 7 | /// 1. has 1 or 2 signatures; 8 | /// 2. is legacy message; 9 | /// 3. has only one instruction; 10 | /// 4. which must be Vote instruction; 11 | pub fn is_simple_vote_transaction( 12 | sanitized_versioned_transaction: &SanitizedVersionedTransaction, 13 | ) -> bool { 14 | let is_legacy_message = matches!( 15 | sanitized_versioned_transaction.message.message, 16 | VersionedMessage::Legacy(_) 17 | ); 18 | let instruction_programs = sanitized_versioned_transaction 19 | .message 20 | .program_instructions_iter() 21 | .map(|(program_id, _ix)| program_id); 22 | 23 | is_simple_vote_transaction_impl( 24 | &sanitized_versioned_transaction.signatures, 25 | is_legacy_message, 26 | instruction_programs, 27 | ) 28 | } 29 | 30 | /// Simple vote transaction meets these conditions: 31 | /// 1. has 1 or 2 signatures; 32 | /// 2. is legacy message; 33 | /// 3. has only one instruction; 34 | /// 4. which must be Vote instruction; 35 | #[inline] 36 | pub fn is_simple_vote_transaction_impl<'a>( 37 | signatures: &[Signature], 38 | is_legacy_message: bool, 39 | mut instruction_programs: impl Iterator, 40 | ) -> bool { 41 | signatures.len() < 3 42 | && is_legacy_message 43 | && instruction_programs 44 | .next() 45 | .xor(instruction_programs.next()) 46 | .map(|program_id| program_id == &solana_sdk_ids::vote::ID) 47 | .unwrap_or(false) 48 | } 49 | -------------------------------------------------------------------------------- /account/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-account" 3 | description = "Solana Account type" 4 | documentation = "https://docs.rs/solana-account" 5 | version = "3.2.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = ["dep:bincode", "dep:solana-sysvar", "serde"] 19 | dev-context-only-utils = ["bincode", "dep:qualifier_attr"] 20 | frozen-abi = [ 21 | "dep:solana-frozen-abi", 22 | "dep:solana-frozen-abi-macro", 23 | "solana-pubkey/frozen-abi", 24 | ] 25 | serde = [ 26 | "dep:serde", 27 | "dep:serde_bytes", 28 | "dep:serde_derive", 29 | "solana-pubkey/serde", 30 | ] 31 | 32 | [dependencies] 33 | bincode = { workspace = true, optional = true } 34 | qualifier_attr = { workspace = true, optional = true } 35 | serde = { workspace = true, optional = true } 36 | serde_bytes = { workspace = true, optional = true } 37 | serde_derive = { workspace = true, optional = true } 38 | solana-account-info = { workspace = true } 39 | solana-clock = { workspace = true } 40 | solana-frozen-abi = { workspace = true, optional = true } 41 | solana-frozen-abi-macro = { workspace = true, optional = true } 42 | solana-instruction-error = { workspace = true } 43 | solana-pubkey = { workspace = true } 44 | solana-sdk-ids = { workspace = true } 45 | solana-sysvar = { workspace = true, features = ["bincode"], optional = true } 46 | 47 | [dev-dependencies] 48 | solana-account = { path = ".", features = ["dev-context-only-utils"] } 49 | solana-pubkey = { workspace = true, features = ["std"] } 50 | -------------------------------------------------------------------------------- /scripts/cliff.toml: -------------------------------------------------------------------------------- 1 | # git-cliff configuration file 2 | # https://git-cliff.org/docs/configuration 3 | [changelog] 4 | header = """ 5 | ## What's new 6 | """ 7 | body = """ 8 | {% for group, commits in commits | group_by(attribute="group") %}\ 9 | {% for commit in commits %} 10 | - {{ commit.message | upper_first | split(pat="\n") | first | trim }}\ 11 | {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif %}\ 12 | {% endfor %}\ 13 | {% endfor %} 14 | """ 15 | # remove the leading and trailing whitespace from the template 16 | trim = true 17 | footer = """ 18 | """ 19 | postprocessors = [ ] 20 | [git] 21 | # parse the commits based on https://www.conventionalcommits.org 22 | conventional_commits = true 23 | # filter out the commits that are not conventional 24 | filter_unconventional = false 25 | # process each line of a commit as an individual commit 26 | split_commits = false 27 | # regex for preprocessing the commit messages 28 | commit_preprocessors = [] 29 | # regex for parsing and grouping commits 30 | commit_parsers = [ 31 | { message = "^build\\(deps\\)", skip = true }, 32 | { message = "^build\\(deps-dev\\)", skip = true }, 33 | { message = "^ci", skip = true }, 34 | { body = ".*", group = "Changes" }, 35 | ] 36 | # protect breaking changes from being skipped due to matching a skipping commit_parser 37 | protect_breaking_commits = false 38 | # filter out the commits that are not matched by commit parsers 39 | filter_commits = false 40 | # glob pattern for matching git tags 41 | tag_pattern = "v[0-9]*" 42 | # regex for skipping tags 43 | skip_tags = "" 44 | # regex for ignoring tags 45 | ignore_tags = "" 46 | # sort the tags topologically 47 | topo_order = false 48 | # sort the commits inside sections by oldest/newest order 49 | sort_commits = "newest" 50 | -------------------------------------------------------------------------------- /feature-gate-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-feature-gate-interface" 3 | description = "Solana feature gate program interface." 4 | documentation = "https://docs.rs/solana-feature-gate-interface" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | rust-version = "1.81.0" 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [features] 17 | bincode = [ 18 | "dep:bincode", 19 | "dep:solana-account", 20 | "dep:solana-account-info", 21 | "dep:solana-instruction", 22 | "dep:solana-rent", 23 | "dep:solana-system-interface", 24 | "serde", 25 | ] 26 | dev-context-only-utils = ["bincode"] 27 | serde = ["dep:serde", "dep:serde_derive"] 28 | 29 | [dependencies] 30 | bincode = { workspace = true, optional = true } 31 | serde = { workspace = true, optional = true } 32 | serde_derive = { workspace = true, optional = true } 33 | solana-account = { workspace = true, optional = true } 34 | solana-account-info = { workspace = true, optional = true } 35 | solana-instruction = { workspace = true, optional = true } 36 | solana-program-error = { workspace = true } 37 | solana-pubkey = { workspace = true } 38 | solana-rent = { workspace = true, optional = true } 39 | solana-sdk-ids = { workspace = true } 40 | solana-system-interface = { workspace = true, optional = true, features = [ 41 | "bincode", 42 | ] } 43 | 44 | [dev-dependencies] 45 | solana-feature-gate-interface = { path = ".", features = ["dev-context-only-utils"] } 46 | solana-pubkey = { workspace = true, features = ["std"] } 47 | strum = { workspace = true } 48 | strum_macros = { workspace = true } 49 | 50 | [lints] 51 | workspace = true 52 | -------------------------------------------------------------------------------- /sdk/src/example_mocks.rs: -------------------------------------------------------------------------------- 1 | //! Mock types for use in examples. 2 | //! 3 | //! These represent APIs from crates that themselves depend on this crate, and 4 | //! which are useful for illustrating the examples for APIs in this crate. 5 | //! 6 | //! Directly depending on these crates though would cause problematic circular 7 | //! dependencies, so instead they are mocked out here in a way that allows 8 | //! examples to appear to use crates that this crate must not depend on. 9 | //! 10 | //! Each mod here has the name of a crate, so that examples can be structured to 11 | //! appear to import from that crate. 12 | 13 | #![doc(hidden)] 14 | #![cfg(feature = "full")] 15 | 16 | pub mod solana_rpc_client { 17 | pub mod rpc_client { 18 | use { 19 | super::super::solana_rpc_client_api::client_error::Result as ClientResult, 20 | crate::{hash::Hash, signature::Signature, transaction::Transaction}, 21 | }; 22 | 23 | pub struct RpcClient; 24 | 25 | impl RpcClient { 26 | pub fn new(_url: String) -> Self { 27 | RpcClient 28 | } 29 | pub fn get_latest_blockhash(&self) -> ClientResult { 30 | Ok(Hash::default()) 31 | } 32 | pub fn send_and_confirm_transaction( 33 | &self, 34 | _transaction: &Transaction, 35 | ) -> ClientResult { 36 | Ok(Signature::default()) 37 | } 38 | } 39 | } 40 | } 41 | 42 | pub mod solana_rpc_client_api { 43 | pub mod client_error { 44 | use thiserror::Error; 45 | 46 | #[derive(Error, Debug)] 47 | #[error("mock-error")] 48 | pub struct ClientError; 49 | pub type Result = std::result::Result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /loader-v4-interface/src/state.rs: -------------------------------------------------------------------------------- 1 | use solana_pubkey::Pubkey; 2 | 3 | #[repr(u64)] 4 | #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] 5 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] 6 | pub enum LoaderV4Status { 7 | /// Program is in maintenance 8 | Retracted, 9 | /// Program is ready to be executed 10 | Deployed, 11 | /// Same as `Deployed`, but can not be retracted anymore 12 | Finalized, 13 | } 14 | 15 | /// LoaderV4 account states 16 | #[repr(C)] 17 | #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] 18 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] 19 | pub struct LoaderV4State { 20 | /// Slot in which the program was last deployed, retracted or initialized. 21 | pub slot: u64, 22 | /// Address of signer which can send program management instructions when the status is not finalized. 23 | /// Otherwise a forwarding to the next version of the finalized program. 24 | pub authority_address_or_next_version: Pubkey, 25 | /// Deployment status. 26 | pub status: LoaderV4Status, 27 | // The raw program data follows this serialized structure in the 28 | // account's data. 29 | } 30 | 31 | impl LoaderV4State { 32 | /// Size of a serialized program account. 33 | pub const fn program_data_offset() -> usize { 34 | std::mem::size_of::() 35 | } 36 | } 37 | 38 | #[cfg(test)] 39 | mod tests { 40 | use {super::*, memoffset::offset_of}; 41 | 42 | #[test] 43 | fn test_layout() { 44 | assert_eq!(offset_of!(LoaderV4State, slot), 0x00); 45 | assert_eq!( 46 | offset_of!(LoaderV4State, authority_address_or_next_version), 47 | 0x08 48 | ); 49 | assert_eq!(offset_of!(LoaderV4State, status), 0x28); 50 | assert_eq!(LoaderV4State::program_data_offset(), 0x30); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /poh-config/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Definitions of Solana's proof of history. 2 | #![cfg_attr(docsrs, feature(doc_cfg))] 3 | #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] 4 | 5 | use std::time::Duration; 6 | 7 | // inlined to avoid solana-clock dep 8 | const DEFAULT_TICKS_PER_SECOND: u64 = 160; 9 | #[cfg(test)] 10 | static_assertions::const_assert_eq!( 11 | DEFAULT_TICKS_PER_SECOND, 12 | solana_clock::DEFAULT_TICKS_PER_SECOND 13 | ); 14 | 15 | #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] 16 | #[cfg_attr( 17 | feature = "serde", 18 | derive(serde_derive::Deserialize, serde_derive::Serialize) 19 | )] 20 | #[derive(Clone, Debug, Eq, PartialEq)] 21 | pub struct PohConfig { 22 | /// The target tick rate of the cluster. 23 | pub target_tick_duration: Duration, 24 | 25 | /// The target total tick count to be produced; used for testing only 26 | pub target_tick_count: Option, 27 | 28 | /// How many hashes to roll before emitting the next tick entry. 29 | /// None enables "Low power mode", which makes the validator sleep 30 | /// for `target_tick_duration` instead of hashing 31 | pub hashes_per_tick: Option, 32 | } 33 | 34 | impl PohConfig { 35 | pub fn new_sleep(target_tick_duration: Duration) -> Self { 36 | Self { 37 | target_tick_duration, 38 | hashes_per_tick: None, 39 | target_tick_count: None, 40 | } 41 | } 42 | } 43 | 44 | // the !=0 check was previously done by the unchecked_div_by_const macro 45 | #[cfg(test)] 46 | static_assertions::const_assert!(DEFAULT_TICKS_PER_SECOND != 0); 47 | const DEFAULT_SLEEP_MICROS: u64 = (1000 * 1000) / DEFAULT_TICKS_PER_SECOND; 48 | 49 | impl Default for PohConfig { 50 | fn default() -> Self { 51 | Self::new_sleep(Duration::from_micros(DEFAULT_SLEEP_MICROS)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /program/src/instruction.rs: -------------------------------------------------------------------------------- 1 | pub use solana_instruction::{ 2 | error::InstructionError, AccountMeta, Instruction, ProcessedSiblingInstruction, 3 | TRANSACTION_LEVEL_STACK_HEIGHT, 4 | }; 5 | 6 | /// Returns a sibling instruction from the processed sibling instruction list. 7 | /// 8 | /// The processed sibling instruction list is a reverse-ordered list of 9 | /// successfully processed sibling instructions. For example, given the call flow: 10 | /// 11 | /// A 12 | /// B -> C -> D 13 | /// B -> E 14 | /// B -> F 15 | /// 16 | /// Then B's processed sibling instruction list is: `[A]` 17 | /// Then F's processed sibling instruction list is: `[E, C]` 18 | pub fn get_processed_sibling_instruction(index: usize) -> Option { 19 | #[cfg(target_os = "solana")] 20 | { 21 | solana_instruction::syscalls::get_processed_sibling_instruction(index) 22 | } 23 | 24 | #[cfg(not(target_os = "solana"))] 25 | { 26 | crate::program_stubs::sol_get_processed_sibling_instruction(index) 27 | } 28 | } 29 | 30 | /// Get the current stack height, transaction-level instructions are height 31 | /// TRANSACTION_LEVEL_STACK_HEIGHT, fist invoked inner instruction is height 32 | /// TRANSACTION_LEVEL_STACK_HEIGHT + 1, etc... 33 | pub fn get_stack_height() -> usize { 34 | #[cfg(target_os = "solana")] 35 | { 36 | solana_instruction::syscalls::get_stack_height() 37 | } 38 | 39 | #[cfg(not(target_os = "solana"))] 40 | { 41 | crate::program_stubs::sol_get_stack_height() as usize 42 | } 43 | } 44 | 45 | // TODO: remove this. 46 | /// Addition that returns [`InstructionError::InsufficientFunds`] on overflow. 47 | /// 48 | /// This is an internal utility function. 49 | #[doc(hidden)] 50 | pub fn checked_add(a: u64, b: u64) -> Result { 51 | a.checked_add(b).ok_or(InstructionError::InsufficientFunds) 52 | } 53 | -------------------------------------------------------------------------------- /secp256k1-program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-secp256k1-program" 3 | description = "Instructions for the Solana Secp256k1 native program." 4 | documentation = "https://docs.rs/solana-secp256k1-program" 5 | version = "3.0.0" 6 | authors = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | license = { workspace = true } 10 | edition = { workspace = true } 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | all-features = true 15 | rustdoc-args = ["--cfg=docsrs"] 16 | 17 | [features] 18 | bincode = [ 19 | "dep:bincode", 20 | "dep:solana-instruction", 21 | "dep:solana-sdk-ids", 22 | "serde", 23 | ] 24 | dev-context-only-utils = ["bincode"] 25 | serde = ["dep:serde", "dep:serde_derive"] 26 | 27 | [dependencies] 28 | bincode = { workspace = true, optional = true } 29 | digest = { workspace = true } 30 | k256 = { workspace = true, features = ["ecdsa-core"] } 31 | serde = { workspace = true, optional = true } 32 | serde_derive = { workspace = true, optional = true } 33 | sha3 = { workspace = true } 34 | solana-instruction = { workspace = true, features = ["std"], optional = true } 35 | solana-sdk-ids = { workspace = true, optional = true } 36 | solana-signature = { workspace = true, features = ["std"] } 37 | 38 | [dev-dependencies] 39 | anyhow = { workspace = true } 40 | hex = { workspace = true } 41 | rand = "0.8" # k256 still uses rand_core v0.6 42 | solana-account-info = { workspace = true } 43 | solana-example-mocks = { path = "../example-mocks" } 44 | solana-instruction = { workspace = true } 45 | solana-instructions-sysvar = { workspace = true } 46 | solana-keccak-hasher = { workspace = true, features = ["sha3"] } 47 | solana-msg = { workspace = true, features = ["std"] } 48 | solana-program-error = { workspace = true } 49 | solana-secp256k1-program = { path = ".", features = ["bincode"] } 50 | -------------------------------------------------------------------------------- /program/src/sysvar.rs: -------------------------------------------------------------------------------- 1 | #[deprecated(since = "2.1.0", note = "Use `solana-sysvar-id` crate instead")] 2 | pub use solana_sysvar_id::{declare_deprecated_sysvar_id, declare_sysvar_id, SysvarId}; 3 | #[deprecated(since = "2.2.0", note = "Use `solana-sysvar` crate instead")] 4 | #[allow(deprecated)] 5 | pub use { 6 | solana_sdk_ids::sysvar::{check_id, id, ID}, 7 | solana_sysvar::{ 8 | clock, epoch_rewards, epoch_schedule, fees, last_restart_slot, recent_blockhashes, rent, 9 | rewards, slot_hashes, slot_history, Sysvar, SysvarSerialize, 10 | }, 11 | }; 12 | 13 | pub mod instructions { 14 | #[deprecated(since = "2.2.0", note = "Use solana-instruction crate instead")] 15 | pub use solana_instruction::{BorrowedAccountMeta, BorrowedInstruction}; 16 | #[cfg(not(target_os = "solana"))] 17 | #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] 18 | pub use solana_instructions_sysvar::construct_instructions_data; 19 | #[cfg(all(not(target_os = "solana"), feature = "dev-context-only-utils"))] 20 | #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] 21 | pub use solana_instructions_sysvar::serialize_instructions; 22 | #[cfg(feature = "dev-context-only-utils")] 23 | #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] 24 | pub use solana_instructions_sysvar::{deserialize_instruction, load_instruction_at}; 25 | #[deprecated(since = "2.2.0", note = "Use solana-instructions-sysvar crate instead")] 26 | #[allow(deprecated)] 27 | pub use solana_instructions_sysvar::{ 28 | get_instruction_relative, load_current_index_checked, load_instruction_at_checked, 29 | Instructions, 30 | }; 31 | #[deprecated(since = "2.2.0", note = "Use solana-sdk-ids crate instead")] 32 | pub use solana_sdk_ids::sysvar::instructions::{check_id, id, ID}; 33 | } 34 | -------------------------------------------------------------------------------- /scripts/check-no-std.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | here="$(dirname "$0")" 6 | src_root="$(readlink -f "${here}/..")" 7 | 8 | cd "${src_root}" 9 | 10 | no_std_crates=( 11 | -p solana-address 12 | -p solana-account-view 13 | -p solana-blake3-hasher 14 | -p solana-clock 15 | -p solana-cluster-type 16 | -p solana-commitment-config 17 | -p solana-define-syscall 18 | -p solana-epoch-info 19 | -p solana-epoch-rewards 20 | -p solana-epoch-schedule 21 | -p solana-epoch-stake 22 | -p solana-fee-calculator 23 | -p solana-hash 24 | -p solana-instruction-view 25 | -p solana-keccak-hasher 26 | -p solana-msg 27 | -p solana-program-error 28 | -p solana-program-log 29 | -p solana-program-log-macro 30 | -p solana-program-memory 31 | -p solana-program-pack 32 | -p solana-pubkey 33 | -p solana-rent 34 | -p solana-sanitize 35 | -p solana-sdk-ids 36 | -p solana-sha256-hasher 37 | -p solana-signature 38 | -p solana-sysvar-id 39 | -p solana-system-interface 40 | ) 41 | # Use the upstream BPF target, which doesn't support std, to make sure that our 42 | # no_std support really works. 43 | target="bpfel-unknown-none" 44 | 45 | # These features require alloc 46 | exclude_features_no_alloc="alloc,borsh,curve25519,serde,slice-cpi" 47 | # These features never work on upstream BPF 48 | exclude_features="atomic,bincode,default,dev-context-only-utils,frozen-abi,rand,std,verify" 49 | 50 | ./cargo nightly hack check \ 51 | -Zbuild-std=core \ 52 | "--target=$target" \ 53 | "--exclude-features=${exclude_features},${exclude_features_no_alloc}" \ 54 | --each-feature \ 55 | "${no_std_crates[@]}" 56 | 57 | # Check that all crates with features that work with no_std + alloc still work! 58 | ./cargo nightly hack check \ 59 | -Zbuild-std=alloc,core \ 60 | "--target=${target}" \ 61 | "--exclude-features=${exclude_features}" \ 62 | --each-feature \ 63 | "${no_std_crates[@]}" 64 | -------------------------------------------------------------------------------- /keypair/src/seed_derivable.rs: -------------------------------------------------------------------------------- 1 | //! Implementation of the SeedDerivable trait for Keypair 2 | 3 | use { 4 | crate::{keypair_from_seed, keypair_from_seed_phrase_and_passphrase, Keypair}, 5 | ed25519_dalek_bip32::Error as Bip32Error, 6 | solana_derivation_path::DerivationPath, 7 | solana_seed_derivable::SeedDerivable, 8 | std::error, 9 | }; 10 | 11 | impl SeedDerivable for Keypair { 12 | fn from_seed(seed: &[u8]) -> Result> { 13 | keypair_from_seed(seed) 14 | } 15 | 16 | fn from_seed_and_derivation_path( 17 | seed: &[u8], 18 | derivation_path: Option, 19 | ) -> Result> { 20 | keypair_from_seed_and_derivation_path(seed, derivation_path) 21 | } 22 | 23 | fn from_seed_phrase_and_passphrase( 24 | seed_phrase: &str, 25 | passphrase: &str, 26 | ) -> Result> { 27 | keypair_from_seed_phrase_and_passphrase(seed_phrase, passphrase) 28 | } 29 | } 30 | 31 | /// Generates a Keypair using Bip32 Hierarchical Derivation if derivation-path is provided; 32 | /// otherwise generates the base Bip44 Solana keypair from the seed 33 | pub fn keypair_from_seed_and_derivation_path( 34 | seed: &[u8], 35 | derivation_path: Option, 36 | ) -> Result> { 37 | let derivation_path = derivation_path.unwrap_or_default(); 38 | bip32_derived_keypair(seed, derivation_path).map_err(|err| err.to_string().into()) 39 | } 40 | 41 | /// Generates a Keypair using Bip32 Hierarchical Derivation 42 | fn bip32_derived_keypair( 43 | seed: &[u8], 44 | derivation_path: DerivationPath, 45 | ) -> Result { 46 | let extended = ed25519_dalek_bip32::ExtendedSigningKey::from_seed(seed) 47 | .and_then(|extended| extended.derive(&derivation_path))?; 48 | Ok(Keypair(extended.signing_key)) 49 | } 50 | -------------------------------------------------------------------------------- /hash/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solana-hash" 3 | description = "Solana wrapper for the 32-byte output of a hashing algorithm." 4 | documentation = "https://docs.rs/solana-hash" 5 | version = "4.0.1" 6 | rust-version = "1.81.0" 7 | authors = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | license = { workspace = true } 11 | edition = { workspace = true } 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] 15 | all-features = true 16 | rustdoc-args = ["--cfg=docsrs"] 17 | 18 | [features] 19 | atomic = ["dep:solana-atomic-u64"] 20 | borsh = ["dep:borsh"] 21 | bytemuck = ["copy", "dep:bytemuck", "dep:bytemuck_derive"] 22 | copy = [] 23 | decode = ["dep:five8"] 24 | default = [] 25 | frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"] 26 | sanitize = ["dep:solana-sanitize"] 27 | serde = ["dep:serde", "dep:serde_derive"] 28 | std = ["borsh?/std", "serde?/std", "wincode?/std"] 29 | wincode = ["dep:wincode"] 30 | 31 | [dependencies] 32 | borsh = { workspace = true, optional = true } 33 | bytemuck = { workspace = true, optional = true } 34 | bytemuck_derive = { workspace = true, optional = true } 35 | five8 = { workspace = true, optional = true } 36 | serde = { workspace = true, optional = true } 37 | serde_derive = { workspace = true, optional = true } 38 | solana-atomic-u64 = { workspace = true, optional = true } 39 | solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } 40 | solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } 41 | solana-sanitize = { workspace = true, optional = true } 42 | wincode = { workspace = true, optional = true } 43 | 44 | [dev-dependencies] 45 | bs58 = { workspace = true, default-features = false, features = ["alloc"] } 46 | solana-hash = { path = ".", features = ["atomic", "copy", "decode"] } 47 | 48 | [lints] 49 | workspace = true 50 | -------------------------------------------------------------------------------- /scripts/check-porcelain.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | here="$(dirname "$0")" 5 | src_root="$(readlink -f "${here}/..")" 6 | cd "${src_root}" 7 | 8 | ( 9 | if [[ -n "$GITHUB_BASE_REF" ]]; then 10 | branch="$GITHUB_BASE_REF" 11 | remote=origin 12 | else 13 | IFS='/' read -r remote branch < <(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null) || true 14 | if [[ -z "$branch" ]]; then 15 | branch="$remote" 16 | remote= 17 | fi 18 | fi 19 | 20 | if [[ -n "$remote" ]] && ! git remote | grep --quiet "^$remote\$" 2>/dev/null; then 21 | echo "WARNING: Remote \`$remote\` not configured for this working directory. Assuming it is actually part of the branch name" 22 | branch="$remote"/"$branch" 23 | remote= 24 | fi 25 | 26 | if [[ -z "$branch" || -z "$remote" ]]; then 27 | msg="Cannot determine remote target branch. Set one with \`git branch --set-upstream-to=TARGET\`" 28 | if [[ -n "$CI" ]]; then 29 | echo "ERROR: $msg" 1>&2 30 | exit 1 31 | else 32 | echo "WARNING: $msg" 1>&2 33 | fi 34 | fi 35 | 36 | # Look for failed mergify.io backports by searching leftover conflict markers 37 | # Also check for any trailing whitespaces! 38 | if [[ -n "$remote" ]]; then 39 | echo "Checking remote \`$remote\` for updates to target branch \`$branch\`" 40 | git fetch --quiet "$remote" "$branch" 41 | target="$remote"/"$branch" 42 | else 43 | echo "WARNING: Target branch \`$branch\` appears to be local. No remote updates will be considered." 44 | target="$branch" 45 | fi 46 | set -x 47 | git diff "$target" --check --oneline 48 | ) 49 | 50 | # Disallow uncommitted Cargo.lock changes 51 | ( 52 | cargo tree >/dev/null 53 | set +e 54 | if ! git diff --exit-code; then 55 | cat <&2 56 | 57 | Error: Uncommitted Cargo.lock changes. 58 | Run 'cargo tree' and commit the result. 59 | EOF 60 | exit 1 61 | fi 62 | ) 63 | -------------------------------------------------------------------------------- /feature-gate-interface/src/error.rs: -------------------------------------------------------------------------------- 1 | //! Program error types. 2 | 3 | use solana_program_error::{ProgramError, ToStr}; 4 | 5 | /// Program error types. 6 | #[cfg_attr(test, derive(strum_macros::FromRepr, strum_macros::EnumIter))] 7 | #[cfg_attr( 8 | feature = "serde", 9 | derive(serde_derive::Deserialize, serde_derive::Serialize) 10 | )] 11 | #[derive(Clone, Debug, PartialEq, Eq)] 12 | #[repr(u32)] 13 | pub enum FeatureGateError { 14 | /// Feature already activated 15 | FeatureAlreadyActivated, 16 | } 17 | 18 | impl core::error::Error for FeatureGateError {} 19 | 20 | impl core::fmt::Display for FeatureGateError { 21 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 22 | f.write_str(self.to_str()) 23 | } 24 | } 25 | 26 | impl ToStr for FeatureGateError { 27 | fn to_str(&self) -> &'static str { 28 | match self { 29 | FeatureGateError::FeatureAlreadyActivated => "Feature already activated", 30 | } 31 | } 32 | } 33 | 34 | impl From for ProgramError { 35 | fn from(e: FeatureGateError) -> Self { 36 | ProgramError::Custom(e as u32) 37 | } 38 | } 39 | 40 | impl TryFrom for FeatureGateError { 41 | type Error = ProgramError; 42 | fn try_from(error: u32) -> Result { 43 | match error { 44 | 0 => Ok(FeatureGateError::FeatureAlreadyActivated), 45 | _ => Err(ProgramError::InvalidArgument), 46 | } 47 | } 48 | } 49 | 50 | #[cfg(test)] 51 | mod tests { 52 | use {super::FeatureGateError, strum::IntoEnumIterator}; 53 | 54 | #[test] 55 | fn test_system_error_from_primitive_exhaustive() { 56 | for variant in FeatureGateError::iter() { 57 | let variant_u32 = variant.clone() as u32; 58 | assert_eq!(FeatureGateError::from_repr(variant_u32).unwrap(), variant); 59 | assert_eq!(FeatureGateError::try_from(variant_u32).unwrap(), variant); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /bincode/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Contains a single utility function for deserializing from [bincode]. 2 | //! 3 | //! [bincode]: https://docs.rs/bincode 4 | #![cfg_attr(docsrs, feature(doc_cfg))] 5 | 6 | use {bincode::config::Options, solana_instruction_error::InstructionError}; 7 | 8 | /// Deserialize with a limit based the maximum amount of data a program can expect to get. 9 | /// This function should be used in place of direct deserialization to help prevent OOM errors 10 | pub fn limited_deserialize(instruction_data: &[u8], limit: u64) -> Result 11 | where 12 | T: serde_core::de::DeserializeOwned, 13 | { 14 | bincode::options() 15 | .with_limit(limit) 16 | .with_fixint_encoding() // As per https://github.com/servo/bincode/issues/333, these two options are needed 17 | .allow_trailing_bytes() // to retain the behavior of bincode::deserialize with the new `options()` method 18 | .deserialize_from(instruction_data) 19 | .map_err(|_| InstructionError::InvalidInstructionData) 20 | } 21 | 22 | #[cfg(test)] 23 | pub mod tests { 24 | use {super::*, solana_system_interface::instruction::SystemInstruction}; 25 | 26 | #[test] 27 | fn test_limited_deserialize_advance_nonce_account() { 28 | let item = SystemInstruction::AdvanceNonceAccount; 29 | let mut serialized = bincode::serialize(&item).unwrap(); 30 | 31 | assert_eq!( 32 | serialized.len(), 33 | 4, 34 | "`SanitizedMessage::get_durable_nonce()` may need a change" 35 | ); 36 | 37 | assert_eq!( 38 | limited_deserialize::(&serialized, 4).as_ref(), 39 | Ok(&item) 40 | ); 41 | assert!(limited_deserialize::(&serialized, 3).is_err()); 42 | 43 | serialized.push(0); 44 | assert_eq!( 45 | limited_deserialize::(&serialized, 4).as_ref(), 46 | Ok(&item) 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /bls-signatures/src/proof_of_possession/points.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(target_os = "solana"))] 2 | use { 3 | crate::{error::BlsError, pubkey::VerifiablePubkey}, 4 | blstrs::{G2Affine, G2Projective}, 5 | }; 6 | 7 | /// A trait for types that can be converted into a `ProofOfPossessionProjective`. 8 | #[cfg(not(target_os = "solana"))] 9 | pub trait AsProofOfPossessionProjective { 10 | /// Attempt to convert the type into a `ProofOfPossessionProjective`. 11 | fn try_as_projective(&self) -> Result; 12 | } 13 | 14 | /// A trait that provides verification methods to any convertible proof of possession type. 15 | #[cfg(not(target_os = "solana"))] 16 | pub trait VerifiableProofOfPossession: AsProofOfPossessionAffine + Sized { 17 | /// Verifies the proof of possession against any convertible public key type. 18 | fn verify( 19 | &self, 20 | pubkey: &P, 21 | payload: Option<&[u8]>, 22 | ) -> Result { 23 | pubkey.verify_proof_of_possession(self, payload) 24 | } 25 | } 26 | 27 | /// A BLS proof of possession in a projective point representation. 28 | #[cfg(not(target_os = "solana"))] 29 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 30 | pub struct ProofOfPossessionProjective(pub(crate) G2Projective); 31 | 32 | #[cfg(not(target_os = "solana"))] 33 | impl VerifiableProofOfPossession for T {} 34 | 35 | /// A trait for types that can be converted into a `ProofOfPossessionAffine`. 36 | #[cfg(not(target_os = "solana"))] 37 | pub trait AsProofOfPossessionAffine { 38 | /// Attempt to convert the type into a `ProofOfPossessionAffine`. 39 | fn try_as_affine(&self) -> Result; 40 | } 41 | 42 | /// A BLS proof of possession in an affine point representation. 43 | #[cfg(not(target_os = "solana"))] 44 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 45 | #[repr(transparent)] 46 | pub struct ProofOfPossessionAffine(pub(crate) G2Affine); 47 | --------------------------------------------------------------------------------