From 2888b575bec1474a458e44302bfd48097e86a3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 28 Nov 2024 12:20:40 +0000 Subject: [PATCH 1/3] Bumps solana_rbpf to v0.9.0 --- Cargo.lock | 59 ++++---- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- cli/src/program.rs | 2 +- cli/src/program_v4.rs | 2 +- ledger-tool/Cargo.toml | 2 +- ledger-tool/src/program.rs | 4 +- program-runtime/Cargo.toml | 4 +- program-runtime/src/invoke_context.rs | 12 +- program-runtime/src/lib.rs | 2 +- program-runtime/src/loaded_programs.rs | 4 +- program-runtime/src/mem_pool.rs | 2 +- program-test/Cargo.toml | 2 +- program-test/src/lib.rs | 4 +- programs/bpf_loader/Cargo.toml | 4 +- programs/bpf_loader/src/lib.rs | 22 +-- programs/bpf_loader/src/serialization.rs | 2 +- programs/bpf_loader/src/syscalls/cpi.rs | 28 ++-- programs/bpf_loader/src/syscalls/logging.rs | 2 +- programs/bpf_loader/src/syscalls/mem_ops.rs | 136 +++++++++--------- programs/bpf_loader/src/syscalls/mod.rs | 131 +++++++++-------- ...lx-r10-sbfv1.so => sbpfv0_verifier_err.so} | Bin .../test_elfs/out/sbpfv3_return_err.so | Bin 0 -> 13816 bytes .../test_elfs/out/sbpfv3_return_ok.so | Bin 0 -> 14840 bytes programs/loader-v4/Cargo.toml | 4 +- programs/loader-v4/src/lib.rs | 57 ++++---- programs/sbf/Cargo.lock | 51 +++---- programs/sbf/Cargo.toml | 4 +- programs/sbf/benches/bpf_loader.rs | 10 +- programs/sbf/tests/programs.rs | 2 +- runtime/src/bank/tests.rs | 8 +- sdk/feature-set/src/lib.rs | 23 ++- svm/Cargo.toml | 2 +- svm/examples/Cargo.lock | 49 +++---- .../json-rpc/server/src/svm_bridge.rs | 9 +- svm/examples/paytube/src/log.rs | 2 +- svm/src/account_loader.rs | 2 +- svm/src/program_loader.rs | 2 +- svm/src/transaction_processor.rs | 2 +- svm/tests/mock_bank.rs | 9 +- 40 files changed, 337 insertions(+), 327 deletions(-) rename programs/bpf_loader/test_elfs/out/{callx-r10-sbfv1.so => sbpfv0_verifier_err.so} (100%) create mode 100644 programs/bpf_loader/test_elfs/out/sbpfv3_return_err.so create mode 100644 programs/bpf_loader/test_elfs/out/sbpfv3_return_ok.so diff --git a/Cargo.lock b/Cargo.lock index b68e5bf9a0f345..9903853c361201 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,6 +197,7 @@ dependencies = [ "solana-rpc", "solana-runtime", "solana-runtime-transaction", + "solana-sbpf", "solana-sdk", "solana-stake-program", "solana-storage-bigtable", @@ -206,7 +207,6 @@ dependencies = [ "solana-unified-scheduler-pool", "solana-version", "solana-vote-program", - "solana_rbpf", "thiserror 2.0.7", "tikv-jemallocator", "tokio", @@ -5357,12 +5357,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "scroll" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" - [[package]] name = "sct" version = "0.7.0" @@ -6232,10 +6226,10 @@ dependencies = [ "solana-poseidon", "solana-program-memory", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-timings", "solana-type-overrides", - "solana_rbpf", "test-case", "thiserror 2.0.7", ] @@ -6453,6 +6447,7 @@ dependencies = [ "solana-rpc-client", "solana-rpc-client-api", "solana-rpc-client-nonce-utils", + "solana-sbpf", "solana-sdk", "solana-streamer", "solana-test-validator", @@ -6462,7 +6457,6 @@ dependencies = [ "solana-udp-client", "solana-version", "solana-vote-program", - "solana_rbpf", "spl-memo", "tempfile", "test-case", @@ -7590,9 +7584,9 @@ dependencies = [ "solana-log-collector", "solana-measure", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-type-overrides", - "solana_rbpf", ] [[package]] @@ -8177,6 +8171,7 @@ dependencies = [ "solana-precompiles", "solana-pubkey", "solana-rent", + "solana-sbpf", "solana-sdk-ids", "solana-slot-hashes", "solana-stable-layout", @@ -8185,7 +8180,6 @@ dependencies = [ "solana-timings", "solana-transaction-context", "solana-type-overrides", - "solana_rbpf", "test-case", "thiserror 2.0.7", ] @@ -8215,12 +8209,12 @@ dependencies = [ "solana-logger", "solana-program-runtime", "solana-runtime", + "solana-sbpf", "solana-sdk", "solana-stake-program", "solana-svm", "solana-timings", "solana-vote-program", - "solana_rbpf", "test-case", "thiserror 2.0.7", "tokio", @@ -8720,6 +8714,25 @@ dependencies = [ name = "solana-sanitize" version = "2.2.0" +[[package]] +name = "solana-sbpf" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b4c060a707fdb0754a876cbbf49591b60a573b5521b485125d2a4d6ff68ce3" +dependencies = [ + "byteorder", + "combine 3.8.1", + "gdbstub", + "hash32", + "libc", + "log", + "rand 0.8.5", + "rustc-demangle", + "shuttle", + "thiserror 1.0.69", + "winapi 0.3.9", +] + [[package]] name = "solana-sdk" version = "2.2.0" @@ -9234,6 +9247,7 @@ dependencies = [ "solana-logger", "solana-measure", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-secp256r1-program", "solana-svm", @@ -9243,7 +9257,6 @@ dependencies = [ "solana-system-program", "solana-timings", "solana-type-overrides", - "solana_rbpf", "test-case", "thiserror 2.0.7", ] @@ -10093,26 +10106,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" -dependencies = [ - "byteorder", - "combine 3.8.1", - "gdbstub", - "hash32", - "libc", - "log", - "rand 0.8.5", - "rustc-demangle", - "scroll", - "shuttle", - "thiserror 1.0.69", - "winapi 0.3.9", -] - [[package]] name = "spin" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 0f33cb5a75b2ec..706de4035e32c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -569,6 +569,7 @@ solana-rpc-client-api = { path = "rpc-client-api", version = "=2.2.0" } solana-rpc-client-nonce-utils = { path = "rpc-client-nonce-utils", version = "=2.2.0" } solana-runtime = { path = "runtime", version = "=2.2.0" } solana-runtime-transaction = { path = "runtime-transaction", version = "=2.2.0" } +solana-sbpf = "=0.9.0" solana-sdk = { path = "sdk", version = "=2.2.0" } solana-sdk-ids = { path = "sdk/sdk-ids", version = "=2.2.0" } solana-sdk-macro = { path = "sdk/macro", version = "=2.2.0" } @@ -612,7 +613,6 @@ solana-zk-keygen = { path = "zk-keygen", version = "=2.2.0" } solana-zk-sdk = { path = "zk-sdk", version = "=2.2.0" } solana-zk-token-proof-program = { path = "programs/zk-token-proof", version = "=2.2.0" } solana-zk-token-sdk = { path = "zk-token-sdk", version = "=2.2.0" } -solana_rbpf = "=0.8.5" spl-associated-token-account = "=6.0.0" spl-instruction-padding = "0.3" spl-memo = "=6.0.0" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 3c5c8372aeaeb7..69ff4d0d9263ec 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -48,6 +48,7 @@ solana-remote-wallet = { workspace = true, features = ["default"] } solana-rpc-client = { workspace = true, features = ["default"] } solana-rpc-client-api = { workspace = true } solana-rpc-client-nonce-utils = { workspace = true, features = ["clap"] } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true } solana-streamer = { workspace = true } solana-tps-client = { workspace = true } @@ -56,7 +57,6 @@ solana-transaction-status = { workspace = true } solana-udp-client = { workspace = true } solana-version = { workspace = true } solana-vote-program = { workspace = true } -solana_rbpf = { workspace = true } spl-memo = { workspace = true, features = ["no-entrypoint"] } thiserror = { workspace = true } tiny-bip39 = { workspace = true } diff --git a/cli/src/program.rs b/cli/src/program.rs index bed71f96470474..577ba91950c63b 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -42,7 +42,6 @@ use { solana_compute_budget::compute_budget::ComputeBudget, solana_feature_set::{FeatureSet, FEATURE_NAMES}, solana_program_runtime::invoke_context::InvokeContext, - solana_rbpf::{elf::Executable, verifier::RequisiteVerifier}, solana_remote_wallet::remote_wallet::RemoteWalletManager, solana_rpc_client::rpc_client::RpcClient, solana_rpc_client_api::{ @@ -52,6 +51,7 @@ use { request::MAX_MULTIPLE_ACCOUNTS, }, solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery, + solana_sbpf::{elf::Executable, verifier::RequisiteVerifier}, solana_sdk::{ account::Account, account_utils::StateMut, diff --git a/cli/src/program_v4.rs b/cli/src/program_v4.rs index 37093db5d73b91..026c096b201839 100644 --- a/cli/src/program_v4.rs +++ b/cli/src/program_v4.rs @@ -26,7 +26,6 @@ use { }, solana_compute_budget::compute_budget::ComputeBudget, solana_program_runtime::invoke_context::InvokeContext, - solana_rbpf::{elf::Executable, verifier::RequisiteVerifier}, solana_remote_wallet::remote_wallet::RemoteWalletManager, solana_rpc_client::rpc_client::RpcClient, solana_rpc_client_api::{ @@ -34,6 +33,7 @@ use { filter::{Memcmp, RpcFilterType}, request::MAX_MULTIPLE_ACCOUNTS, }, + solana_sbpf::{elf::Executable, verifier::RequisiteVerifier}, solana_sdk::{ account::Account, feature_set::{FeatureSet, FEATURE_NAMES}, diff --git a/ledger-tool/Cargo.toml b/ledger-tool/Cargo.toml index bb232fcc768ab7..cc2f5918a497e7 100644 --- a/ledger-tool/Cargo.toml +++ b/ledger-tool/Cargo.toml @@ -47,6 +47,7 @@ solana-program-runtime = { workspace = true } solana-rpc = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-runtime-transaction = { workspace = true } +solana-sbpf = { workspace = true, features = ["debugger"] } solana-sdk = { workspace = true, features = ["openssl-vendored"] } solana-stake-program = { workspace = true } solana-storage-bigtable = { workspace = true } @@ -56,7 +57,6 @@ solana-type-overrides = { workspace = true } solana-unified-scheduler-pool = { workspace = true } solana-version = { workspace = true } solana-vote-program = { workspace = true } -solana_rbpf = { workspace = true, features = ["debugger"] } thiserror = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/ledger-tool/src/program.rs b/ledger-tool/src/program.rs index 55015a1bee2105..92165d4d9bab60 100644 --- a/ledger-tool/src/program.rs +++ b/ledger-tool/src/program.rs @@ -17,11 +17,11 @@ use { }, with_mock_invoke_context, }, - solana_rbpf::{ + solana_runtime::bank::Bank, + solana_sbpf::{ assembler::assemble, elf::Executable, static_analysis::Analysis, verifier::RequisiteVerifier, }, - solana_runtime::bank::Bank, solana_sdk::{ account::{create_account_shared_data_for_test, AccountSharedData}, account_utils::StateMut, diff --git a/program-runtime/Cargo.toml b/program-runtime/Cargo.toml index a29ab0cef9ed82..ca323514669ba6 100644 --- a/program-runtime/Cargo.toml +++ b/program-runtime/Cargo.toml @@ -41,6 +41,7 @@ solana-metrics = { workspace = true } solana-precompiles = { workspace = true } solana-pubkey = { workspace = true } solana-rent = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk-ids = { workspace = true } solana-slot-hashes = { workspace = true } solana-stable-layout = { workspace = true } @@ -49,7 +50,6 @@ solana-sysvar-id = { workspace = true } solana-timings = { workspace = true } solana-transaction-context = { workspace = true } solana-type-overrides = { workspace = true } -solana_rbpf = { workspace = true } thiserror = { workspace = true } [dev-dependencies] @@ -76,7 +76,7 @@ frozen-abi = [ ] shuttle-test = [ "solana-type-overrides/shuttle-test", - "solana_rbpf/shuttle-test", + "solana-sbpf/shuttle-test", ] [lints] diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index db6486a6194dd6..6e47e2622a65fc 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -21,7 +21,7 @@ use { solana_measure::measure::Measure, solana_precompiles::Precompile, solana_pubkey::Pubkey, - solana_rbpf::{ + solana_sbpf::{ ebpf::MM_HEAP_START, error::{EbpfError, ProgramResult}, memory_region::MemoryMapping, @@ -49,7 +49,7 @@ pub type BuiltinFunctionWithContext = BuiltinFunction>; #[macro_export] macro_rules! declare_process_instruction { ($process_instruction:ident, $cu_to_consume:expr, |$invoke_context:ident| $inner:tt) => { - $crate::solana_rbpf::declare_builtin_function!( + $crate::solana_sbpf::declare_builtin_function!( $process_instruction, fn rust( invoke_context: &mut $crate::invoke_context::InvokeContext, @@ -58,7 +58,7 @@ macro_rules! declare_process_instruction { _arg2: u64, _arg3: u64, _arg4: u64, - _memory_mapping: &mut $crate::solana_rbpf::memory_region::MemoryMapping, + _memory_mapping: &mut $crate::solana_sbpf::memory_region::MemoryMapping, ) -> std::result::Result> { fn process_instruction_inner( $invoke_context: &mut $crate::invoke_context::InvokeContext, @@ -536,7 +536,7 @@ impl<'a> InvokeContext<'a> { .ok_or(InstructionError::UnsupportedProgramId)?; let function = match &entry.program { ProgramCacheEntryType::Builtin(program) => program - .get_function_registry() + .get_function_registry(SBPFVersion::V0) .lookup_by_key(ENTRYPOINT_KEY) .map(|(_name, function)| function), _ => None, @@ -555,13 +555,13 @@ impl<'a> InvokeContext<'a> { // For now, only built-ins are invoked from here, so the VM and its Config are irrelevant. let mock_config = Config::default(); let empty_memory_mapping = - MemoryMapping::new(Vec::new(), &mock_config, &SBPFVersion::V1).unwrap(); + MemoryMapping::new(Vec::new(), &mock_config, SBPFVersion::V1).unwrap(); let mut vm = EbpfVm::new( self.program_cache_for_tx_batch .environments .program_runtime_v2 .clone(), - &SBPFVersion::V1, + SBPFVersion::V0, // Removes lifetime tracking unsafe { std::mem::transmute::<&mut InvokeContext, &mut InvokeContext>(self) }, empty_memory_mapping, diff --git a/program-runtime/src/lib.rs b/program-runtime/src/lib.rs index 974ecee64f94d4..3adf1ae222a6b7 100644 --- a/program-runtime/src/lib.rs +++ b/program-runtime/src/lib.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate solana_metrics; -pub use solana_rbpf; +pub use solana_sbpf; pub mod invoke_context; pub mod loaded_programs; pub mod mem_pool; diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 9e11477ea897bb..20399d6f1f34b0 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -5,7 +5,7 @@ use { solana_clock::{Epoch, Slot}, solana_measure::measure::Measure, solana_pubkey::Pubkey, - solana_rbpf::{ + solana_sbpf::{ elf::Executable, program::{BuiltinProgram, FunctionRegistry}, verifier::RequisiteVerifier, @@ -1370,7 +1370,7 @@ mod tests { percentage::Percentage, solana_clock::Slot, solana_pubkey::Pubkey, - solana_rbpf::{elf::Executable, program::BuiltinProgram}, + solana_sbpf::{elf::Executable, program::BuiltinProgram}, std::{ fs::File, io::Read, diff --git a/program-runtime/src/mem_pool.rs b/program-runtime/src/mem_pool.rs index a92ec1603ddb27..0c39557605bfe6 100644 --- a/program-runtime/src/mem_pool.rs +++ b/program-runtime/src/mem_pool.rs @@ -3,7 +3,7 @@ use { compute_budget::{MAX_CALL_DEPTH, MAX_INSTRUCTION_STACK_DEPTH, STACK_FRAME_SIZE}, compute_budget_limits::{MAX_HEAP_FRAME_BYTES, MIN_HEAP_FRAME_BYTES}, }, - solana_rbpf::{aligned_memory::AlignedMemory, ebpf::HOST_ALIGN}, + solana_sbpf::{aligned_memory::AlignedMemory, ebpf::HOST_ALIGN}, std::array, }; diff --git a/program-test/Cargo.toml b/program-test/Cargo.toml index d3df42d38abe44..3eb57298f8e281 100644 --- a/program-test/Cargo.toml +++ b/program-test/Cargo.toml @@ -30,11 +30,11 @@ solana-log-collector = { workspace = true } solana-logger = { workspace = true } solana-program-runtime = { workspace = true } solana-runtime = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true } solana-svm = { workspace = true } solana-timings = { workspace = true } solana-vote-program = { workspace = true } -solana_rbpf = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index 1115330888d8a4..c3d0d9f5d00dd1 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -69,7 +69,7 @@ pub use { solana_banks_client::{BanksClient, BanksClientError}, solana_banks_interface::BanksTransactionResultWithMetadata, solana_program_runtime::invoke_context::InvokeContext, - solana_rbpf::{ + solana_sbpf::{ error::EbpfError, vm::{get_runtime_environment_key, EbpfVm}, }, @@ -497,7 +497,7 @@ impl Default for ProgramTest { /// fn default() -> Self { solana_logger::setup_with_default( - "solana_rbpf::vm=debug,\ + "solana_sbpf::vm=debug,\ solana_runtime::message_processor=debug,\ solana_runtime::system_instruction_processor=trace,\ solana_program_test=info", diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 3c62ccc69fcfa1..fc99553d3fefe4 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -24,10 +24,10 @@ solana-measure = { workspace = true } solana-poseidon = { workspace = true } solana-program-memory = { workspace = true } solana-program-runtime = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true } solana-timings = { workspace = true } solana-type-overrides = { workspace = true } -solana_rbpf = { workspace = true } thiserror = { workspace = true } [dev-dependencies] @@ -48,5 +48,5 @@ targets = ["x86_64-unknown-linux-gnu"] shuttle-test = [ "solana-type-overrides/shuttle-test", "solana-program-runtime/shuttle-test", - "solana_rbpf/shuttle-test" + "solana-sbpf/shuttle-test" ] diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 38240e455d5f02..5b65d610afe18d 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -22,7 +22,7 @@ use { stable_log, sysvar_cache::get_sysvar_with_account_check, }, - solana_rbpf::{ + solana_sbpf::{ declare_builtin_function, ebpf::{self, MM_HEAP_START}, elf::Executable, @@ -326,16 +326,16 @@ macro_rules! create_vm { macro_rules! mock_create_vm { ($vm:ident, $additional_regions:expr, $accounts_metadata:expr, $invoke_context:expr $(,)?) => { let loader = solana_type_overrides::sync::Arc::new(BuiltinProgram::new_mock()); - let function_registry = solana_rbpf::program::FunctionRegistry::default(); - let executable = solana_rbpf::elf::Executable::::from_text_bytes( - &[0x95, 0, 0, 0, 0, 0, 0, 0], + let function_registry = solana_sbpf::program::FunctionRegistry::default(); + let executable = solana_sbpf::elf::Executable::::from_text_bytes( + &[0x9D, 0, 0, 0, 0, 0, 0, 0], loader, - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); executable - .verify::() + .verify::() .unwrap(); $crate::create_vm!( $vm, @@ -1696,7 +1696,7 @@ mod tests { let loader_id = bpf_loader::id(); let program_id = Pubkey::new_unique(); let program_account = - load_program_account_from_elf(&loader_id, "test_elfs/out/noop_aligned.so"); + load_program_account_from_elf(&loader_id, "test_elfs/out/sbpfv3_return_ok.so"); let parameter_id = Pubkey::new_unique(); let parameter_account = AccountSharedData::new(1, 0, &loader_id); let parameter_meta = AccountMeta { @@ -2184,10 +2184,10 @@ mod tests { #[test] fn test_bpf_loader_upgradeable_upgrade() { - let mut file = File::open("test_elfs/out/noop_aligned.so").expect("file open failed"); + let mut file = File::open("test_elfs/out/sbpfv3_return_ok.so").expect("file open failed"); let mut elf_orig = Vec::new(); file.read_to_end(&mut elf_orig).unwrap(); - let mut file = File::open("test_elfs/out/noop_unaligned.so").expect("file open failed"); + let mut file = File::open("test_elfs/out/sbpfv3_return_err.so").expect("file open failed"); let mut elf_new = Vec::new(); file.read_to_end(&mut elf_new).unwrap(); assert_ne!(elf_orig.len(), elf_new.len()); @@ -3783,7 +3783,7 @@ mod tests { let program_id = Pubkey::new_unique(); // Create program account - let mut file = File::open("test_elfs/out/noop_aligned.so").expect("file open failed"); + let mut file = File::open("test_elfs/out/sbpfv3_return_ok.so").expect("file open failed"); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); @@ -3833,7 +3833,7 @@ mod tests { invoke_context: &mut InvokeContext, program_id: Pubkey, ) -> Result<(), InstructionError> { - let mut file = File::open("test_elfs/out/noop_unaligned.so").expect("file open failed"); + let mut file = File::open("test_elfs/out/sbpfv3_return_ok.so").expect("file open failed"); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); deploy_program!( diff --git a/programs/bpf_loader/src/serialization.rs b/programs/bpf_loader/src/serialization.rs index 15c5820dc23924..e04fd730aa7c80 100644 --- a/programs/bpf_loader/src/serialization.rs +++ b/programs/bpf_loader/src/serialization.rs @@ -3,7 +3,7 @@ use { byteorder::{ByteOrder, LittleEndian}, solana_program_runtime::invoke_context::SerializedAccountMetadata, - solana_rbpf::{ + solana_sbpf::{ aligned_memory::{AlignedMemory, Pod}, ebpf::{HOST_ALIGN, MM_INPUT_START}, memory_region::{MemoryRegion, MemoryState}, diff --git a/programs/bpf_loader/src/syscalls/cpi.rs b/programs/bpf_loader/src/syscalls/cpi.rs index bb0179da75d14c..8492363d2f6808 100644 --- a/programs/bpf_loader/src/syscalls/cpi.rs +++ b/programs/bpf_loader/src/syscalls/cpi.rs @@ -5,7 +5,7 @@ use { solana_feature_set::{self as feature_set, enable_bpf_loader_set_authority_checked_ix}, solana_measure::measure::Measure, solana_program_runtime::invoke_context::SerializedAccountMetadata, - solana_rbpf::{ + solana_sbpf::{ ebpf, memory_region::{MemoryRegion, MemoryState}, }, @@ -1609,7 +1609,7 @@ mod tests { solana_program_runtime::{ invoke_context::SerializedAccountMetadata, with_mock_invoke_context, }, - solana_rbpf::{ + solana_sbpf::{ ebpf::MM_INPUT_START, memory_region::MemoryRegion, program::SBPFVersion, vm::Config, }, solana_sdk::{ @@ -1710,7 +1710,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![region], &config, SBPFVersion::V3).unwrap(); let ins = SyscallInvokeSignedRust::translate_instruction( vm_addr, @@ -1746,7 +1746,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![region], &config, SBPFVersion::V3).unwrap(); let signers = SyscallInvokeSignedRust::translate_signers( &program_id, @@ -1782,7 +1782,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![region], &config, SBPFVersion::V3).unwrap(); let account_info = translate_type::(&memory_mapping, vm_addr, false).unwrap(); @@ -1832,7 +1832,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1890,7 +1890,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2018,7 +2018,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2193,7 +2193,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2263,7 +2263,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2319,7 +2319,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2392,7 +2392,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2480,7 +2480,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2558,7 +2558,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![region], &config, SBPFVersion::V3).unwrap(); mock_invoke_context!( invoke_context, diff --git a/programs/bpf_loader/src/syscalls/logging.rs b/programs/bpf_loader/src/syscalls/logging.rs index 522145b1d71408..83dcee9055cfcf 100644 --- a/programs/bpf_loader/src/syscalls/logging.rs +++ b/programs/bpf_loader/src/syscalls/logging.rs @@ -1,4 +1,4 @@ -use {super::*, solana_rbpf::vm::ContextObject}; +use {super::*, solana_sbpf::vm::ContextObject}; declare_builtin_function!( /// Log a user's info message diff --git a/programs/bpf_loader/src/syscalls/mem_ops.rs b/programs/bpf_loader/src/syscalls/mem_ops.rs index e6db37ccaa29bf..254828e3c5e2db 100644 --- a/programs/bpf_loader/src/syscalls/mem_ops.rs +++ b/programs/bpf_loader/src/syscalls/mem_ops.rs @@ -1,7 +1,7 @@ use { super::*, solana_program_runtime::invoke_context::SerializedAccountMetadata, - solana_rbpf::{error::EbpfError, memory_region::MemoryRegion}, + solana_sbpf::{error::EbpfError, memory_region::MemoryRegion}, std::slice, }; @@ -573,7 +573,7 @@ mod tests { use { super::*, assert_matches::assert_matches, - solana_rbpf::{ebpf::MM_PROGRAM_START, program::SBPFVersion}, + solana_sbpf::{ebpf::MM_RODATA_START, program::SBPFVersion}, test_case::test_case, }; @@ -591,7 +591,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); let mut src_chunk_iter = MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, 0, 1).unwrap(); @@ -605,7 +605,7 @@ mod tests { aligned_memory_mapping: false, ..Config::default() }; - let memory_mapping = MemoryMapping::new(vec![], &config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); let mut src_chunk_iter = MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, u64::MAX, 1).unwrap(); @@ -620,9 +620,9 @@ mod tests { }; let mem1 = vec![0xFF; 42]; let memory_mapping = MemoryMapping::new( - vec![MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START)], + vec![MemoryRegion::new_readonly(&mem1, MM_RODATA_START)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -631,34 +631,34 @@ mod tests { &memory_mapping, &[], AccessType::Load, - MM_PROGRAM_START - 1, + MM_RODATA_START - 1, 42, ) .unwrap(); assert_matches!( src_chunk_iter.next().unwrap().unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 42, "unknown") if *addr == MM_PROGRAM_START - 1 + EbpfError::AccessViolation(AccessType::Load, addr, 42, "unknown") if *addr == MM_RODATA_START - 1 ); // check oob at the upper bound. Since the memory mapping isn't empty, // this always happens on the second next(). let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, MM_PROGRAM_START, 43) + MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, MM_RODATA_START, 43) .unwrap(); assert!(src_chunk_iter.next().unwrap().is_ok()); assert_matches!( src_chunk_iter.next().unwrap().unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 43, "program") if *addr == MM_PROGRAM_START + EbpfError::AccessViolation(AccessType::Load, addr, 43, "program") if *addr == MM_RODATA_START ); // check oob at the upper bound on the first next_back() let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, MM_PROGRAM_START, 43) + MemoryChunkIterator::new(&memory_mapping, &[], AccessType::Load, MM_RODATA_START, 43) .unwrap() .rev(); assert_matches!( src_chunk_iter.next().unwrap().unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 43, "program") if *addr == MM_PROGRAM_START + EbpfError::AccessViolation(AccessType::Load, addr, 43, "program") if *addr == MM_RODATA_START ); // check oob at the upper bound on the 2nd next_back() @@ -666,7 +666,7 @@ mod tests { &memory_mapping, &[], AccessType::Load, - MM_PROGRAM_START - 1, + MM_RODATA_START - 1, 43, ) .unwrap() @@ -674,7 +674,7 @@ mod tests { assert!(src_chunk_iter.next().unwrap().is_ok()); assert_matches!( src_chunk_iter.next().unwrap().unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 43, "unknown") if *addr == MM_PROGRAM_START - 1 + EbpfError::AccessViolation(AccessType::Load, addr, 43, "unknown") if *addr == MM_RODATA_START - 1 ); } @@ -686,9 +686,9 @@ mod tests { }; let mem1 = vec![0xFF; 42]; let memory_mapping = MemoryMapping::new( - vec![MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START)], + vec![MemoryRegion::new_readonly(&mem1, MM_RODATA_START)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -697,7 +697,7 @@ mod tests { &memory_mapping, &[], AccessType::Load, - MM_PROGRAM_START - 1, + MM_RODATA_START - 1, 1, ) .unwrap(); @@ -708,18 +708,18 @@ mod tests { &memory_mapping, &[], AccessType::Load, - MM_PROGRAM_START + 42, + MM_RODATA_START + 42, 1, ) .unwrap(); assert!(src_chunk_iter.next().unwrap().is_err()); for (vm_addr, len) in [ - (MM_PROGRAM_START, 0), - (MM_PROGRAM_START + 42, 0), - (MM_PROGRAM_START, 1), - (MM_PROGRAM_START, 42), - (MM_PROGRAM_START + 41, 1), + (MM_RODATA_START, 0), + (MM_RODATA_START + 42, 0), + (MM_RODATA_START, 1), + (MM_RODATA_START, 42), + (MM_RODATA_START + 41, 1), ] { for rev in [true, false] { let iter = @@ -749,22 +749,22 @@ mod tests { let mem2 = vec![0x22; 4]; let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START), - MemoryRegion::new_readonly(&mem2, MM_PROGRAM_START + 8), + MemoryRegion::new_readonly(&mem1, MM_RODATA_START), + MemoryRegion::new_readonly(&mem2, MM_RODATA_START + 8), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); for (vm_addr, len, mut expected) in [ - (MM_PROGRAM_START, 8, vec![(MM_PROGRAM_START, 8)]), + (MM_RODATA_START, 8, vec![(MM_RODATA_START, 8)]), ( - MM_PROGRAM_START + 7, + MM_RODATA_START + 7, 2, - vec![(MM_PROGRAM_START + 7, 1), (MM_PROGRAM_START + 8, 1)], + vec![(MM_RODATA_START + 7, 1), (MM_RODATA_START + 8, 1)], ), - (MM_PROGRAM_START + 8, 4, vec![(MM_PROGRAM_START + 8, 4)]), + (MM_RODATA_START + 8, 4, vec![(MM_RODATA_START + 8, 4)]), ] { for rev in [false, true] { let iter = @@ -792,11 +792,11 @@ mod tests { let mem2 = vec![0x22; 4]; let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START), - MemoryRegion::new_readonly(&mem2, MM_PROGRAM_START + 8), + MemoryRegion::new_readonly(&mem1, MM_RODATA_START), + MemoryRegion::new_readonly(&mem2, MM_RODATA_START + 8), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -804,32 +804,32 @@ mod tests { assert_matches!( iter_memory_pair_chunks( AccessType::Load, - MM_PROGRAM_START, + MM_RODATA_START, AccessType::Load, - MM_PROGRAM_START + 8, + MM_RODATA_START + 8, 8, &[], &memory_mapping, false, |_src, _dst, _len| Ok::<_, Error>(0), ).unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 8, "program") if *addr == MM_PROGRAM_START + 8 + EbpfError::AccessViolation(AccessType::Load, addr, 8, "program") if *addr == MM_RODATA_START + 8 ); // src is shorter than dst assert_matches!( iter_memory_pair_chunks( AccessType::Load, - MM_PROGRAM_START + 10, + MM_RODATA_START + 10, AccessType::Load, - MM_PROGRAM_START + 2, + MM_RODATA_START + 2, 3, &[], &memory_mapping, false, |_src, _dst, _len| Ok::<_, Error>(0), ).unwrap_err().downcast_ref().unwrap(), - EbpfError::AccessViolation(AccessType::Load, addr, 3, "program") if *addr == MM_PROGRAM_START + 10 + EbpfError::AccessViolation(AccessType::Load, addr, 3, "program") if *addr == MM_RODATA_START + 10 ); } @@ -844,17 +844,17 @@ mod tests { let mem2 = vec![0x22; 4]; let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START), - MemoryRegion::new_readonly(&mem2, MM_PROGRAM_START + 8), + MemoryRegion::new_readonly(&mem1, MM_RODATA_START), + MemoryRegion::new_readonly(&mem2, MM_RODATA_START + 8), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); memmove_non_contiguous( - MM_PROGRAM_START, - MM_PROGRAM_START + 8, + MM_RODATA_START, + MM_RODATA_START + 8, 4, &[], &memory_mapping, @@ -903,8 +903,8 @@ mod tests { // do our memmove memmove_non_contiguous( - MM_PROGRAM_START + dst_offset as u64, - MM_PROGRAM_START + src_offset as u64, + MM_RODATA_START + dst_offset as u64, + MM_RODATA_START + src_offset as u64, len as u64, &[], &memory_mapping, @@ -929,16 +929,16 @@ mod tests { let mem2 = vec![0x22; 4]; let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_writable(&mut mem1, MM_PROGRAM_START), - MemoryRegion::new_readonly(&mem2, MM_PROGRAM_START + 8), + MemoryRegion::new_writable(&mut mem1, MM_RODATA_START), + MemoryRegion::new_readonly(&mem2, MM_RODATA_START + 8), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_eq!( - memset_non_contiguous(MM_PROGRAM_START, 0x33, 9, &[], &memory_mapping).unwrap(), + memset_non_contiguous(MM_RODATA_START, 0x33, 9, &[], &memory_mapping).unwrap(), 0 ); } @@ -955,18 +955,18 @@ mod tests { let mut mem4 = vec![0x44; 4]; let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START), - MemoryRegion::new_writable(&mut mem2, MM_PROGRAM_START + 1), - MemoryRegion::new_writable(&mut mem3, MM_PROGRAM_START + 3), - MemoryRegion::new_writable(&mut mem4, MM_PROGRAM_START + 6), + MemoryRegion::new_readonly(&mem1, MM_RODATA_START), + MemoryRegion::new_writable(&mut mem2, MM_RODATA_START + 1), + MemoryRegion::new_writable(&mut mem3, MM_RODATA_START + 3), + MemoryRegion::new_writable(&mut mem4, MM_RODATA_START + 6), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_eq!( - memset_non_contiguous(MM_PROGRAM_START + 1, 0x55, 7, &[], &memory_mapping).unwrap(), + memset_non_contiguous(MM_RODATA_START + 1, 0x55, 7, &[], &memory_mapping).unwrap(), 0 ); assert_eq!(&mem1, &[0x11]); @@ -986,20 +986,20 @@ mod tests { let mem3 = b"foobarbad".to_vec(); let memory_mapping = MemoryMapping::new( vec![ - MemoryRegion::new_readonly(&mem1, MM_PROGRAM_START), - MemoryRegion::new_readonly(&mem2, MM_PROGRAM_START + 3), - MemoryRegion::new_readonly(&mem3, MM_PROGRAM_START + 9), + MemoryRegion::new_readonly(&mem1, MM_RODATA_START), + MemoryRegion::new_readonly(&mem2, MM_RODATA_START + 3), + MemoryRegion::new_readonly(&mem3, MM_RODATA_START + 9), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); // non contiguous src assert_eq!( memcmp_non_contiguous( - MM_PROGRAM_START, - MM_PROGRAM_START + 9, + MM_RODATA_START, + MM_RODATA_START + 9, 9, &[], &memory_mapping @@ -1011,8 +1011,8 @@ mod tests { // non contiguous dst assert_eq!( memcmp_non_contiguous( - MM_PROGRAM_START + 10, - MM_PROGRAM_START + 1, + MM_RODATA_START + 10, + MM_RODATA_START + 1, 8, &[], &memory_mapping @@ -1024,8 +1024,8 @@ mod tests { // diff assert_eq!( memcmp_non_contiguous( - MM_PROGRAM_START + 1, - MM_PROGRAM_START + 11, + MM_RODATA_START + 1, + MM_RODATA_START + 11, 5, &[], &memory_mapping @@ -1050,12 +1050,12 @@ mod tests { ); regs.push(MemoryRegion::new_writable( &mut mem[i], - MM_PROGRAM_START + offset as u64, + MM_RODATA_START + offset as u64, )); offset += *region_len; } - let memory_mapping = MemoryMapping::new(regs, config, &SBPFVersion::V2).unwrap(); + let memory_mapping = MemoryMapping::new(regs, config, SBPFVersion::V3).unwrap(); (mem, memory_mapping) } diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 3438c819c74bbe..1117fd4c631f14 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -21,21 +21,22 @@ use { solana_feature_set::{ self as feature_set, abort_on_invalid_curve, blake3_syscall_enabled, bpf_account_data_direct_mapping, curve25519_syscall_enabled, - disable_deploy_of_alloc_free_syscall, disable_fees_sysvar, disable_sbpf_v1_execution, + disable_deploy_of_alloc_free_syscall, disable_fees_sysvar, disable_sbpf_v0_execution, enable_alt_bn128_compression_syscall, enable_alt_bn128_syscall, enable_big_mod_exp_syscall, enable_get_epoch_stake_syscall, enable_partitioned_epoch_reward, enable_poseidon_syscall, - get_sysvar_syscall_enabled, last_restart_slot_sysvar, - partitioned_epoch_rewards_superfeature, reenable_sbpf_v1_execution, - remaining_compute_units_syscall_enabled, FeatureSet, + enable_sbpf_v1_deployment_and_execution, enable_sbpf_v2_deployment_and_execution, + enable_sbpf_v3_deployment_and_execution, get_sysvar_syscall_enabled, + last_restart_slot_sysvar, partitioned_epoch_rewards_superfeature, + reenable_sbpf_v0_execution, remaining_compute_units_syscall_enabled, FeatureSet, }, solana_log_collector::{ic_logger_msg, ic_msg}, solana_poseidon as poseidon, solana_program_memory::is_nonoverlapping, solana_program_runtime::{invoke_context::InvokeContext, stable_log}, - solana_rbpf::{ + solana_sbpf::{ declare_builtin_function, memory_region::{AccessType, MemoryMapping}, - program::{BuiltinFunction, BuiltinProgram, FunctionRegistry}, + program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion}, vm::Config, }, solana_sdk::{ @@ -244,12 +245,16 @@ macro_rules! register_feature_gated_function { pub fn morph_into_deployment_environment_v1( from: Arc>, ) -> Result, Error> { - let mut config = *from.get_config(); + let mut config = from.get_config().clone(); config.reject_broken_elfs = true; + // Once the tests are being build using a toolchain which supports the newer SBPF versions, + // the deployment of older versions will be disabled: + // config.enabled_sbpf_versions = + // *config.enabled_sbpf_versions.end()..=*config.enabled_sbpf_versions.end(); let mut result = FunctionRegistry::>::default(); - for (key, (name, value)) in from.get_function_registry().iter() { + for (key, (name, value)) in from.get_function_registry(SBPFVersion::V0).iter() { // Deployment of programs with sol_alloc_free is disabled. So do not register the syscall. if name != *b"sol_alloc_free_" { result.register_function(key, name, value)?; @@ -284,6 +289,23 @@ pub fn create_program_runtime_environment_v1<'a>( let get_sysvar_syscall_enabled = feature_set.is_active(&get_sysvar_syscall_enabled::id()); let enable_get_epoch_stake_syscall = feature_set.is_active(&enable_get_epoch_stake_syscall::id()); + let min_sbpf_version = if !feature_set.is_active(&disable_sbpf_v0_execution::id()) + || feature_set.is_active(&reenable_sbpf_v0_execution::id()) + { + SBPFVersion::V0 + } else { + SBPFVersion::V3 + }; + let max_sbpf_version = if feature_set.is_active(&enable_sbpf_v3_deployment_and_execution::id()) + { + SBPFVersion::V3 + } else if feature_set.is_active(&enable_sbpf_v2_deployment_and_execution::id()) { + SBPFVersion::V2 + } else if feature_set.is_active(&enable_sbpf_v1_deployment_and_execution::id()) { + SBPFVersion::V1 + } else { + SBPFVersion::V0 + }; let config = Config { max_call_depth: compute_budget.max_call_depth, @@ -297,11 +319,7 @@ pub fn create_program_runtime_environment_v1<'a>( reject_broken_elfs: reject_deployment_of_broken_elfs, noop_instruction_rate: 256, sanitize_user_provided_values: true, - external_internal_function_hash_collision: true, - reject_callx_r10: true, - enable_sbpf_v1: !feature_set.is_active(&disable_sbpf_v1_execution::id()) - || feature_set.is_active(&reenable_sbpf_v1_execution::id()), - enable_sbpf_v2: false, + enabled_sbpf_versions: min_sbpf_version..=max_sbpf_version, optimize_rodata: false, aligned_memory_mapping: !feature_set.is_active(&bpf_account_data_direct_mapping::id()), // Warning, do not use `Config::default()` so that configuration here is explicit. @@ -504,10 +522,7 @@ pub fn create_program_runtime_environment_v2<'a>( reject_broken_elfs: true, noop_instruction_rate: 256, sanitize_user_provided_values: true, - external_internal_function_hash_collision: true, - reject_callx_r10: true, - enable_sbpf_v1: false, - enable_sbpf_v2: true, + enabled_sbpf_versions: SBPFVersion::Reserved..=SBPFVersion::Reserved, optimize_rodata: true, aligned_memory_mapping: true, // Warning, do not use `Config::default()` so that configuration here is explicit. @@ -1848,7 +1863,7 @@ declare_builtin_function!( let budget = invoke_context.get_compute_budget(); consume_compute_meter(invoke_context, budget.syscall_base_cost)?; - use solana_rbpf::vm::ContextObject; + use solana_sbpf::vm::ContextObject; Ok(invoke_context.get_remaining()) } ); @@ -2120,7 +2135,7 @@ mod tests { assert_matches::assert_matches, core::slice, solana_program_runtime::{invoke_context::InvokeContext, with_mock_invoke_context}, - solana_rbpf::{ + solana_sbpf::{ error::EbpfError, memory_region::MemoryRegion, program::SBPFVersion, vm::Config, }, solana_sdk::{ @@ -2191,7 +2206,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(&data, START)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2232,7 +2247,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(bytes_of(&pubkey), 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_pubkey = @@ -2248,14 +2263,14 @@ mod tests { let instruction = StableInstruction::from(instruction); let memory_region = MemoryRegion::new_readonly(bytes_of(&instruction), 0x100000000); let memory_mapping = - MemoryMapping::new(vec![memory_region], &config, &SBPFVersion::V2).unwrap(); + MemoryMapping::new(vec![memory_region], &config, SBPFVersion::V3).unwrap(); let translated_instruction = translate_type::(&memory_mapping, 0x100000000, true).unwrap(); assert_eq!(instruction, *translated_instruction); let memory_region = MemoryRegion::new_readonly(&bytes_of(&instruction)[..1], 0x100000000); let memory_mapping = - MemoryMapping::new(vec![memory_region], &config, &SBPFVersion::V2).unwrap(); + MemoryMapping::new(vec![memory_region], &config, SBPFVersion::V3).unwrap(); assert!(translate_type::(&memory_mapping, 0x100000000, true).is_err()); } @@ -2270,7 +2285,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(&good_data, 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2283,7 +2298,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(&data, 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2308,7 +2323,7 @@ mod tests { 0x100000000, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2328,7 +2343,7 @@ mod tests { 0x100000000, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2346,7 +2361,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(string.as_bytes(), 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_eq!( @@ -2370,7 +2385,7 @@ mod tests { fn test_syscall_abort() { prepare_mockup!(invoke_context, program_id, bpf_loader::id()); let config = Config::default(); - let mut memory_mapping = MemoryMapping::new(vec![], &config, &SBPFVersion::V2).unwrap(); + let mut memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); let result = SyscallAbort::rust(&mut invoke_context, 0, 0, 0, 0, 0, &mut memory_mapping); result.unwrap(); } @@ -2385,7 +2400,7 @@ mod tests { let mut memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(string.as_bytes(), 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2426,7 +2441,7 @@ mod tests { let mut memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(string.as_bytes(), 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2493,7 +2508,7 @@ mod tests { invoke_context.mock_set_remaining(cost); let config = Config::default(); - let mut memory_mapping = MemoryMapping::new(vec![], &config, &SBPFVersion::V2).unwrap(); + let mut memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); let result = SyscallLogU64::rust(&mut invoke_context, 1, 2, 3, 4, 5, &mut memory_mapping); result.unwrap(); @@ -2517,7 +2532,7 @@ mod tests { let mut memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(bytes_of(&pubkey), 0x100000000)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2700,7 +2715,7 @@ mod tests { MemoryRegion::new_readonly(bytes2.as_bytes(), bytes_to_hash[1].vm_addr), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2798,7 +2813,7 @@ mod tests { MemoryRegion::new_readonly(&invalid_bytes, invalid_bytes_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2871,7 +2886,7 @@ mod tests { MemoryRegion::new_readonly(&invalid_bytes, invalid_bytes_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2958,7 +2973,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3113,7 +3128,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3283,7 +3298,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3376,7 +3391,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3561,7 +3576,7 @@ mod tests { MemoryRegion::new_readonly(&Clock::id().to_bytes(), clock_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3627,7 +3642,7 @@ mod tests { ), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3689,7 +3704,7 @@ mod tests { got_fees_va, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3728,7 +3743,7 @@ mod tests { MemoryRegion::new_readonly(&Rent::id().to_bytes(), rent_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3788,7 +3803,7 @@ mod tests { MemoryRegion::new_readonly(&EpochRewards::id().to_bytes(), rewards_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3853,7 +3868,7 @@ mod tests { MemoryRegion::new_readonly(&LastRestartSlot::id().to_bytes(), restart_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3938,7 +3953,7 @@ mod tests { MemoryRegion::new_readonly(&StakeHistory::id().to_bytes(), history_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3997,7 +4012,7 @@ mod tests { MemoryRegion::new_readonly(&SlotHashes::id().to_bytes(), hashes_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4043,7 +4058,7 @@ mod tests { MemoryRegion::new_readonly(&got_clock_buf_ro, got_clock_buf_ro_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4232,7 +4247,7 @@ mod tests { bytes_of_slice(&mock_slices), SEEDS_VA, )); - let mut memory_mapping = MemoryMapping::new(regions, &config, &SBPFVersion::V2).unwrap(); + let mut memory_mapping = MemoryMapping::new(regions, &config, SBPFVersion::V3).unwrap(); let result = syscall( invoke_context, @@ -4296,7 +4311,7 @@ mod tests { MemoryRegion::new_writable(&mut id_buffer, PROGRAM_ID_VA), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4396,7 +4411,7 @@ mod tests { let mut memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_writable(&mut memory, VM_BASE_ADDRESS)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let processed_sibling_instruction = translate_type_mut::( @@ -4702,7 +4717,7 @@ mod tests { MemoryRegion::new_writable(&mut data_out, VADDR_OUT), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4744,7 +4759,7 @@ mod tests { MemoryRegion::new_writable(&mut data_out, VADDR_OUT), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4799,7 +4814,7 @@ mod tests { let null_pointer_var = std::ptr::null::() as u64; - let mut memory_mapping = MemoryMapping::new(vec![], &config, &SBPFVersion::V2).unwrap(); + let mut memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); let result = SyscallGetEpochStake::rust( &mut invoke_context, @@ -4863,7 +4878,7 @@ mod tests { MemoryRegion::new_readonly(&[2; 31], vote_address_var), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4893,7 +4908,7 @@ mod tests { vote_address_var, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4925,7 +4940,7 @@ mod tests { vote_address_var, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); diff --git a/programs/bpf_loader/test_elfs/out/callx-r10-sbfv1.so b/programs/bpf_loader/test_elfs/out/sbpfv0_verifier_err.so similarity index 100% rename from programs/bpf_loader/test_elfs/out/callx-r10-sbfv1.so rename to programs/bpf_loader/test_elfs/out/sbpfv0_verifier_err.so diff --git a/programs/bpf_loader/test_elfs/out/sbpfv3_return_err.so b/programs/bpf_loader/test_elfs/out/sbpfv3_return_err.so new file mode 100644 index 0000000000000000000000000000000000000000..fac0efc9da6945c07733812ba238f7d7e31c659e GIT binary patch literal 13816 zcmeHOziSjx5T0COqNY$Ih*-!LVj;Th?cVL}6++HaK1JS9p=$}$tV2G zlYN8n^7ArHK^0I1Q~^~$6;K6K0aZX1Pz6*0RX`QkR|VejpYHF7WWM76zpuH<3-o{D z|5fq#wYUzZ3aA3AfGVI0r~;~hDxeCe0;+&2pbDr02cp1*1F51#Q~^~$6;K6K0aZX1 zPz6*0RX`O`1yli5;D1zr_5#e99RYTB4o~tT$HnLE0s!4d3)Nsy^jDLjyOPCe)(`St zui99N>Twn}tA3t%k)K4(He~BXe{-X^x?TXB<#Ekf0JKlAFEGP~!+4TW>i*c??oo)h zG1xu+oJ0HUr`bNuc!*K<;~! z1>gsIZ{k)BbC=^EF%Fd}*g~M^BA41CUZdXAGmblm)I=|Ei|lCuZoiktMGWrJVBijl zIC*SMd~+M%rkm@7%{7Zf-(bA9nt+SZB3?pV!8dI!i}2f1RArQr!l!)V%Xu65o-u5i(MBA^8eTNE%zq1Q;%{;N zx9C%o_apV?u`c61scjOu^QzYPz&`!H&=|s(`L{79wK>(mSLQz`2hrX+|JxWF#lP-b J;+H-6zW|t0$z=cl literal 0 HcmV?d00001 diff --git a/programs/bpf_loader/test_elfs/out/sbpfv3_return_ok.so b/programs/bpf_loader/test_elfs/out/sbpfv3_return_ok.so new file mode 100644 index 0000000000000000000000000000000000000000..e3cd32871d39ce9c7bcc2841c9e3fe13a0a9a807 GIT binary patch literal 14840 zcmeHO&ubG=5PnH(qxN8}AmTyxARa`Q&2F;U9E8RijaaKvQS=fv`=bfcrX(xai}vEd z|3Q!5Jrun9$LLK#Pl6um%zHC&O#@YIL2w@IelzoC=Dqj5*+AgEXU(On#X>=Gn^GmM zS!7rs3_K%D0W7FM&A@wB9Z?vmqvyzR3H8&3Gm=oiagD=x?E!Y^f!s}qvMtJ4ocA%jdu|@riqxrI(;;^6n5kJyo zUxPirUJ4Ts2801&Ko}4PgaKhd7!U@80bxKG5C-;@fo=NJ{S^?!m-N5)6^-&7^zZP0 zb(?gy@9QKanJ^#>2m``^Fdz&F1HynXAPfit!hkR!3>+u}=MOZyBo_vR0bxKG5C((+ zVL%uV2801&Ko}4Pgn@sV0Xz#ZuTKP+Sz0vN3uI^g6xmh#;d0p6n80wzJbm z6CGnPXZ*L=uR4=+HN%)x4}705+^NtUcKV@t`kDpwy!)`Zrr@SXbAnwH`W3^`c6td7wz}x zz6|wo-LPv31dPw$c|l!S`1)CAM%%3)BcJ@;7tA%fSHm9|CD6G!8Q^L3g(n}cWrv*h zh(8N%_-*Fruj`uP@%zMv{NUKUey(Hu9m4TA9{n-CMe+PSgITxn`B%V-xq1FuAY=R% z#lHa^8}AQ~KWEJ95+ILFCJj#6Xz$2~zb}}B<9Yr~u<_XBs^K%m-_ILC9-sd$uuY1; V=9<7yd&G}*iz*BV1OE{NKL8nG%0U1C literal 0 HcmV?d00001 diff --git a/programs/loader-v4/Cargo.toml b/programs/loader-v4/Cargo.toml index 55e6e702f3e163..ceb3eb2ef4ff47 100644 --- a/programs/loader-v4/Cargo.toml +++ b/programs/loader-v4/Cargo.toml @@ -15,9 +15,9 @@ solana-compute-budget = { workspace = true } solana-log-collector = { workspace = true } solana-measure = { workspace = true } solana-program-runtime = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true } solana-type-overrides = { workspace = true } -solana_rbpf = { workspace = true } [dev-dependencies] bincode = { workspace = true } @@ -30,4 +30,4 @@ name = "solana_loader_v4_program" targets = ["x86_64-unknown-linux-gnu"] [features] -shuttle-test = ["solana-type-overrides/shuttle-test", "solana-program-runtime/shuttle-test", "solana_rbpf/shuttle-test"] +shuttle-test = ["solana-type-overrides/shuttle-test", "solana-program-runtime/shuttle-test", "solana-sbpf/shuttle-test"] diff --git a/programs/loader-v4/src/lib.rs b/programs/loader-v4/src/lib.rs index 78033323e2a1e7..b209f54dbbbe07 100644 --- a/programs/loader-v4/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -6,7 +6,7 @@ use { invoke_context::InvokeContext, loaded_programs::{ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType}, }, - solana_rbpf::{declare_builtin_function, memory_region::MemoryMapping}, + solana_sbpf::{declare_builtin_function, memory_region::MemoryMapping}, solana_sdk::{ instruction::InstructionError, loader_v4::{self, LoaderV4State, LoaderV4Status, DEPLOYMENT_COOLDOWN_IN_SLOTS}, @@ -572,7 +572,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -584,7 +584,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Finalized, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -670,7 +670,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -682,7 +682,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -767,7 +767,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -780,14 +780,14 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(40000000, 0, &loader_v4::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_ok", ), ), ( @@ -795,7 +795,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -807,6 +807,9 @@ mod tests { create_account_shared_data_for_test(&rent::Rent::default()), ), ]; + let smaller_program_lamports = transaction_accounts[0].1.lamports(); + let larger_program_lamports = transaction_accounts[4].1.lamports(); + assert_ne!(smaller_program_lamports, larger_program_lamports); // No change let accounts = process_instruction( @@ -829,10 +832,11 @@ mod tests { transaction_accounts[0].1.data().len(), ); assert_eq!(accounts[2].lamports(), transaction_accounts[2].1.lamports()); - let lamports = transaction_accounts[4].1.lamports(); - transaction_accounts[0].1.set_lamports(lamports); // Initialize program account + transaction_accounts[3] + .1 + .set_lamports(smaller_program_lamports); let accounts = process_instruction( vec![], &bincode::serialize(&LoaderV4Instruction::Truncate { @@ -854,6 +858,9 @@ mod tests { ); // Increase program account size + transaction_accounts[0] + .1 + .set_lamports(larger_program_lamports); let accounts = process_instruction( vec![], &bincode::serialize(&LoaderV4Instruction::Truncate { @@ -1024,7 +1031,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_ok", ), ), ( @@ -1036,7 +1043,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_unaligned", + "sbpfv3_return_err", ), ), ( @@ -1048,7 +1055,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "callx-r10-sbfv1", + "sbpfv0_verifier_err", ), ), (clock::id(), clock(1000)), @@ -1172,7 +1179,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1188,7 +1195,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_err", ), ), (clock::id(), clock(1000)), @@ -1252,7 +1259,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1260,7 +1267,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1347,7 +1354,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Deployed, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1355,7 +1362,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1363,7 +1370,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Finalized, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1371,7 +1378,7 @@ mod tests { load_program_account_from_elf( Pubkey::new_unique(), LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_err", ), ), ( @@ -1487,7 +1494,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Finalized, - "noop_aligned", + "sbpfv3_return_ok", ), ), ( @@ -1503,7 +1510,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Retracted, - "noop_aligned", + "sbpfv3_return_ok", ), ), ( @@ -1511,7 +1518,7 @@ mod tests { load_program_account_from_elf( authority_address, LoaderV4Status::Finalized, - "callx-r10-sbfv1", + "sbpfv0_verifier_err", ), ), ]; diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index f133980765273f..f8b22860d8cdb2 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4546,12 +4546,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "scroll" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" - [[package]] name = "sct" version = "0.7.0" @@ -5132,10 +5126,10 @@ dependencies = [ "solana-poseidon", "solana-program-memory", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-timings", "solana-type-overrides", - "solana_rbpf", "thiserror 2.0.7", ] @@ -6052,9 +6046,9 @@ dependencies = [ "solana-log-collector", "solana-measure", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-type-overrides", - "solana_rbpf", ] [[package]] @@ -6442,6 +6436,7 @@ dependencies = [ "solana-precompiles", "solana-pubkey", "solana-rent", + "solana-sbpf", "solana-sdk-ids", "solana-slot-hashes", "solana-stable-layout", @@ -6450,7 +6445,6 @@ dependencies = [ "solana-timings", "solana-transaction-context", "solana-type-overrides", - "solana_rbpf", "thiserror 2.0.7", ] @@ -6479,11 +6473,11 @@ dependencies = [ "solana-logger", "solana-program-runtime", "solana-runtime", + "solana-sbpf", "solana-sdk", "solana-svm", "solana-timings", "solana-vote-program", - "solana_rbpf", "thiserror 2.0.7", "tokio", ] @@ -6913,6 +6907,7 @@ dependencies = [ "solana-sbf-rust-invoke-dep", "solana-sbf-rust-realloc-dep", "solana-sbf-rust-realloc-invoke-dep", + "solana-sbpf", "solana-sdk", "solana-svm", "solana-svm-transaction", @@ -6921,7 +6916,6 @@ dependencies = [ "solana-type-overrides", "solana-vote", "solana-vote-program", - "solana_rbpf", ] [[package]] @@ -7380,6 +7374,23 @@ dependencies = [ "solana-program", ] +[[package]] +name = "solana-sbpf" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b4c060a707fdb0754a876cbbf49591b60a573b5521b485125d2a4d6ff68ce3" +dependencies = [ + "byteorder 1.5.0", + "combine 3.8.1", + "hash32", + "libc", + "log", + "rand 0.8.5", + "rustc-demangle", + "thiserror 1.0.69", + "winapi 0.3.9", +] + [[package]] name = "solana-sdk" version = "2.2.0" @@ -8411,24 +8422,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" -dependencies = [ - "byteorder 1.5.0", - "combine 3.8.1", - "hash32", - "libc", - "log", - "rand 0.8.5", - "rustc-demangle", - "scroll", - "thiserror 1.0.69", - "winapi 0.3.9", -] - [[package]] name = "spin" version = "0.5.2" diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 63a1bd5e9d4c8b..90be3500204a5f 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -59,6 +59,7 @@ solana-sbf-rust-param-passing-dep = { path = "rust/param_passing_dep", version = solana-sbf-rust-realloc-dep = { path = "rust/realloc_dep", version = "=2.2.0" } solana-sbf-rust-realloc-invoke-dep = { path = "rust/realloc_invoke_dep", version = "=2.2.0" } solana-sdk = { path = "../../sdk", version = "=2.2.0" } +solana-sbpf = "=0.9.0" solana-secp256k1-recover = { path = "../../curves/secp256k1-recover", version = "=2.2.0" } solana-svm = { path = "../../svm", version = "=2.2.0" } solana-svm-transaction = { path = "../../svm-transaction", version = "=2.2.0" } @@ -69,7 +70,6 @@ solana-vote = { path = "../../vote", version = "=2.2.0" } solana-vote-program = { path = "../../programs/vote", version = "=2.2.0" } agave-validator = { path = "../../validator", version = "=2.2.0" } solana-zk-sdk = { path = "../../zk-sdk", version = "=2.2.0" } -solana_rbpf = "=0.8.5" thiserror = "1.0" [package] @@ -130,6 +130,7 @@ solana-runtime-transaction = { workspace = true, features = [ solana-sbf-rust-invoke-dep = { workspace = true } solana-sbf-rust-realloc-dep = { workspace = true } solana-sbf-rust-realloc-invoke-dep = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } solana-svm = { workspace = true } solana-svm-transaction = { workspace = true } @@ -138,7 +139,6 @@ solana-transaction-status = { workspace = true } solana-type-overrides = { workspace = true } solana-vote = { workspace = true } solana-vote-program = { workspace = true } -solana_rbpf = { workspace = true } [[bench]] name = "bpf_loader" diff --git a/programs/sbf/benches/bpf_loader.rs b/programs/sbf/benches/bpf_loader.rs index 7475e9ea2d0f53..c31a2d64f04c06 100644 --- a/programs/sbf/benches/bpf_loader.rs +++ b/programs/sbf/benches/bpf_loader.rs @@ -8,7 +8,7 @@ )] use { - solana_feature_set::bpf_account_data_direct_mapping, solana_rbpf::memory_region::MemoryState, + solana_feature_set::bpf_account_data_direct_mapping, solana_sbpf::memory_region::MemoryState, solana_sdk::signer::keypair::Keypair, std::slice, }; @@ -24,16 +24,16 @@ use { solana_feature_set::FeatureSet, solana_measure::measure::Measure, solana_program_runtime::invoke_context::InvokeContext, - solana_rbpf::{ - ebpf::MM_INPUT_START, elf::Executable, memory_region::MemoryRegion, - verifier::RequisiteVerifier, vm::ContextObject, - }, solana_runtime::{ bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, loader_utils::{load_program_from_file, load_upgradeable_program_and_advance_slot}, }, + solana_sbpf::{ + ebpf::MM_INPUT_START, elf::Executable, memory_region::MemoryRegion, + verifier::RequisiteVerifier, vm::ContextObject, + }, solana_sdk::{ account::AccountSharedData, bpf_loader, diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index d9d6b9c6d54651..5a7877eeaa2d06 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -19,7 +19,7 @@ use { solana_feature_set::{self as feature_set, FeatureSet}, solana_ledger::token_balances::collect_token_balances, solana_program_runtime::{ - invoke_context::mock_process_instruction, solana_rbpf::vm::ContextObject, + invoke_context::mock_process_instruction, solana_sbpf::vm::ContextObject, }, solana_runtime::{ bank::{Bank, TransactionBalancesSet}, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 1cb8c7ab4b5a22..a03674a2231424 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -12087,10 +12087,10 @@ fn test_feature_activation_loaded_programs_cache_preparation_phase() { let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); genesis_config .accounts - .remove(&feature_set::disable_sbpf_v1_execution::id()); + .remove(&feature_set::disable_sbpf_v0_execution::id()); genesis_config .accounts - .remove(&feature_set::reenable_sbpf_v1_execution::id()); + .remove(&feature_set::reenable_sbpf_v0_execution::id()); let (root_bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); // Program Setup @@ -12124,7 +12124,7 @@ fn test_feature_activation_loaded_programs_cache_preparation_phase() { let feature_account_balance = std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1); bank.store_account( - &feature_set::disable_sbpf_v1_execution::id(), + &feature_set::disable_sbpf_v0_execution::id(), &feature::create_account(&Feature { activated_at: None }, feature_account_balance), ); @@ -12199,7 +12199,7 @@ fn test_feature_activation_loaded_programs_epoch_transition() { .remove(&feature_set::disable_fees_sysvar::id()); genesis_config .accounts - .remove(&feature_set::reenable_sbpf_v1_execution::id()); + .remove(&feature_set::reenable_sbpf_v0_execution::id()); let (root_bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); // Program Setup diff --git a/sdk/feature-set/src/lib.rs b/sdk/feature-set/src/lib.rs index 4eefad3ce7112a..449da264ae0978 100644 --- a/sdk/feature-set/src/lib.rs +++ b/sdk/feature-set/src/lib.rs @@ -860,14 +860,26 @@ pub mod deprecate_legacy_vote_ixs { solana_pubkey::declare_id!("depVvnQ2UysGrhwdiwU42tCadZL8GcBb1i2GYhMopQv"); } -pub mod disable_sbpf_v1_execution { +pub mod disable_sbpf_v0_execution { solana_pubkey::declare_id!("TestFeature11111111111111111111111111111111"); } -pub mod reenable_sbpf_v1_execution { +pub mod reenable_sbpf_v0_execution { solana_pubkey::declare_id!("TestFeature21111111111111111111111111111111"); } +pub mod enable_sbpf_v1_deployment_and_execution { + solana_pubkey::declare_id!("JE86WkYvTrzW8HgNmrHY7dFYpCmSptUpKupbo2AdQ9cG"); +} + +pub mod enable_sbpf_v2_deployment_and_execution { + solana_pubkey::declare_id!("F6UVKh1ujTEFK3en2SyAL3cdVnqko1FVEXWhmdLRu6WP"); +} + +pub mod enable_sbpf_v3_deployment_and_execution { + solana_pubkey::declare_id!("C8XZNs1bfzaiT3YDeXZJ7G5swQWQv7tVzDnCxtHvnSpw"); +} + pub mod remove_accounts_executable_flag_checks { solana_pubkey::declare_id!("FfgtauHUWKeXTzjXkua9Px4tNGBFHKZ9WaigM5VbbzFx"); } @@ -1114,8 +1126,11 @@ lazy_static! { (enable_turbine_extended_fanout_experiments::id(), "enable turbine extended fanout experiments #"), (deprecate_legacy_vote_ixs::id(), "Deprecate legacy vote instructions"), (partitioned_epoch_rewards_superfeature::id(), "replaces enable_partitioned_epoch_reward to enable partitioned rewards at epoch boundary SIMD-0118"), - (disable_sbpf_v1_execution::id(), "Disables execution of SBPFv1 programs"), - (reenable_sbpf_v1_execution::id(), "Re-enables execution of SBPFv1 programs"), + (disable_sbpf_v0_execution::id(), "Disables execution of SBPFv1 programs SIMD-0161"), + (reenable_sbpf_v0_execution::id(), "Re-enables execution of SBPFv1 programs"), + (enable_sbpf_v1_deployment_and_execution::id(), "Enables deployment and execution of SBPFv1 programs SIMD-0161"), + (enable_sbpf_v2_deployment_and_execution::id(), "Enables deployment and execution of SBPFv2 programs SIMD-0161"), + (enable_sbpf_v3_deployment_and_execution::id(), "Enables deployment and execution of SBPFv3 programs SIMD-0161"), (remove_accounts_executable_flag_checks::id(), "Remove checks of accounts is_executable flag SIMD-0162"), (lift_cpi_caller_restriction::id(), "Lift the restriction in CPI that the caller must have the callee as an instruction account #2202"), (disable_account_loader_special_case::id(), "Disable account loader special case #3513"), diff --git a/svm/Cargo.toml b/svm/Cargo.toml index e3ed11e14df0f0..4f13eb55e3caff 100644 --- a/svm/Cargo.toml +++ b/svm/Cargo.toml @@ -57,12 +57,12 @@ shuttle = { workspace = true } solana-compute-budget-program = { workspace = true } solana-ed25519-program = { workspace = true } solana-logger = { workspace = true } +solana-sbpf = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] } # See order-crates-for-publishing.py for using this unusual `path = "."` solana-svm = { path = ".", features = ["dev-context-only-utils"] } solana-svm-conformance = { workspace = true } -solana_rbpf = { workspace = true } test-case = { workspace = true } [package.metadata.docs.rs] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 35404e8d55abb4..7540ae2ec468cb 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -4418,12 +4418,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "scroll" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" - [[package]] name = "sct" version = "0.7.1" @@ -4983,10 +4977,10 @@ dependencies = [ "solana-poseidon", "solana-program-memory", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-timings", "solana-type-overrides", - "solana_rbpf", "thiserror 2.0.7", ] @@ -5872,9 +5866,9 @@ dependencies = [ "solana-log-collector", "solana-measure", "solana-program-runtime", + "solana-sbpf", "solana-sdk", "solana-type-overrides", - "solana_rbpf", ] [[package]] @@ -6262,6 +6256,7 @@ dependencies = [ "solana-precompiles", "solana-pubkey", "solana-rent", + "solana-sbpf", "solana-sdk-ids", "solana-slot-hashes", "solana-stable-layout", @@ -6270,7 +6265,6 @@ dependencies = [ "solana-timings", "solana-transaction-context", "solana-type-overrides", - "solana_rbpf", "thiserror 2.0.7", ] @@ -6299,11 +6293,11 @@ dependencies = [ "solana-logger", "solana-program-runtime", "solana-runtime", + "solana-sbpf", "solana-sdk", "solana-svm", "solana-timings", "solana-vote-program", - "solana_rbpf", "thiserror 2.0.7", "tokio", ] @@ -6700,6 +6694,23 @@ dependencies = [ name = "solana-sanitize" version = "2.2.0" +[[package]] +name = "solana-sbpf" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b4c060a707fdb0754a876cbbf49591b60a573b5521b485125d2a4d6ff68ce3" +dependencies = [ + "byteorder", + "combine 3.8.1", + "hash32", + "libc", + "log", + "rand 0.8.5", + "rustc-demangle", + "thiserror 1.0.69", + "winapi 0.3.9", +] + [[package]] name = "solana-sdk" version = "2.2.0" @@ -7747,24 +7758,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" -dependencies = [ - "byteorder", - "combine 3.8.1", - "hash32", - "libc", - "log", - "rand 0.8.5", - "rustc-demangle", - "scroll", - "thiserror 1.0.69", - "winapi 0.3.9", -] - [[package]] name = "spin" version = "0.9.8" diff --git a/svm/examples/json-rpc/server/src/svm_bridge.rs b/svm/examples/json-rpc/server/src/svm_bridge.rs index c136af791c08f0..d0d6371df1d882 100644 --- a/svm/examples/json-rpc/server/src/svm_bridge.rs +++ b/svm/examples/json-rpc/server/src/svm_bridge.rs @@ -12,8 +12,8 @@ use { BlockRelation, ForkGraph, LoadProgramMetrics, ProgramCacheEntry, ProgramRuntimeEnvironments, }, - solana_rbpf::{ - program::{BuiltinFunction, BuiltinProgram, FunctionRegistry}, + solana_sbpf::{ + program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion}, vm::Config, }, }, @@ -154,10 +154,7 @@ pub fn create_custom_environment<'a>() -> BuiltinProgram> { reject_broken_elfs: true, noop_instruction_rate: 256, sanitize_user_provided_values: true, - external_internal_function_hash_collision: false, - reject_callx_r10: false, - enable_sbpf_v1: true, - enable_sbpf_v2: false, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V3, optimize_rodata: false, aligned_memory_mapping: true, }; diff --git a/svm/examples/paytube/src/log.rs b/svm/examples/paytube/src/log.rs index 92c75573080741..040ef237b55284 100644 --- a/svm/examples/paytube/src/log.rs +++ b/svm/examples/paytube/src/log.rs @@ -19,7 +19,7 @@ fn log_magenta(msg: &str) { pub(crate) fn setup_solana_logging() { #[rustfmt::skip] solana_logger::setup_with_default( - "solana_rbpf::vm=debug,\ + "solana_sbpf::vm=debug,\ solana_runtime::message_processor=debug,\ solana_runtime::system_instruction_processor=trace", ); diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 895db94f3b111f..1bb8bc1d7e5d54 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -704,7 +704,7 @@ mod tests { ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType, ProgramCacheForTxBatch, }, - solana_rbpf::program::BuiltinProgram, + solana_sbpf::program::BuiltinProgram, solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, bpf_loader, diff --git a/svm/src/program_loader.rs b/svm/src/program_loader.rs index 553b57fac08634..902eebb0782492 100644 --- a/svm/src/program_loader.rs +++ b/svm/src/program_loader.rs @@ -256,7 +256,7 @@ mod tests { crate::transaction_processor::TransactionBatchProcessor, solana_program_runtime::{ loaded_programs::{BlockRelation, ForkGraph, ProgramRuntimeEnvironments}, - solana_rbpf::program::BuiltinProgram, + solana_sbpf::program::BuiltinProgram, }, solana_sdk::{account::WritableAccount, bpf_loader, bpf_loader_upgradeable}, std::{ diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index e252710ec60499..0736905336325e 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -37,7 +37,7 @@ use { ForkGraph, ProgramCache, ProgramCacheEntry, ProgramCacheForTxBatch, ProgramCacheMatchCriteria, ProgramRuntimeEnvironment, }, - solana_rbpf::{ + solana_sbpf::{ program::{BuiltinProgram, FunctionRegistry}, vm::Config as VmConfig, }, diff --git a/svm/tests/mock_bank.rs b/svm/tests/mock_bank.rs index 6cd692133d219b..6df8eedb3c28f8 100644 --- a/svm/tests/mock_bank.rs +++ b/svm/tests/mock_bank.rs @@ -11,8 +11,8 @@ use { solana_program_runtime::{ invoke_context::InvokeContext, loaded_programs::{BlockRelation, ForkGraph, ProgramCacheEntry}, - solana_rbpf::{ - program::{BuiltinFunction, BuiltinProgram, FunctionRegistry}, + solana_sbpf::{ + program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion}, vm::Config, }, }, @@ -302,10 +302,7 @@ pub fn create_custom_loader<'a>() -> BuiltinProgram> { reject_broken_elfs: true, noop_instruction_rate: 256, sanitize_user_provided_values: true, - external_internal_function_hash_collision: false, - reject_callx_r10: true, - enable_sbpf_v1: true, - enable_sbpf_v2: false, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V3, optimize_rodata: false, aligned_memory_mapping: true, }; From 4c3ccdd9cd66a02b534565dfe4adaf0d17b53af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 16 Dec 2024 17:10:27 +0000 Subject: [PATCH 2/3] Adds dense syscall keys --- programs/bpf_loader/src/syscalls/mod.rs | 127 ++++++++++++++---------- 1 file changed, 73 insertions(+), 54 deletions(-) diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 1117fd4c631f14..4281d43054fb88 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -36,7 +36,7 @@ use { solana_sbpf::{ declare_builtin_function, memory_region::{AccessType, MemoryMapping}, - program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion}, + program::{BuiltinProgram, FunctionRegistry, SBPFVersion}, vm::Config, }, solana_sdk::{ @@ -233,11 +233,11 @@ fn consume_compute_meter(invoke_context: &InvokeContext, amount: u64) -> Result< } macro_rules! register_feature_gated_function { - ($result:expr, $is_feature_active:expr, $name:expr, $call:expr $(,)?) => { + ($result:expr, $is_feature_active:expr, $name:expr, $key:expr, $call:expr $(,)?) => { if $is_feature_active { - $result.register_function_hashed($name, $call) + $result.register_function($name, $key, $call) } else { - Ok(0) + Ok(()) } }; } @@ -252,16 +252,16 @@ pub fn morph_into_deployment_environment_v1( // config.enabled_sbpf_versions = // *config.enabled_sbpf_versions.end()..=*config.enabled_sbpf_versions.end(); - let mut result = FunctionRegistry::>::default(); + let mut result = BuiltinProgram::new_loader_with_dense_registration(config); - for (key, (name, value)) in from.get_function_registry(SBPFVersion::V0).iter() { + for (key, (name, value)) in from.get_function_registry(SBPFVersion::V3).iter() { // Deployment of programs with sol_alloc_free is disabled. So do not register the syscall. if name != *b"sol_alloc_free_" { - result.register_function(key, name, value)?; + result.register_function(unsafe { std::str::from_utf8_unchecked(name) }, key, value)?; } } - Ok(BuiltinProgram::new_loader(config, result)) + Ok(result) } pub fn create_program_runtime_environment_v1<'a>( @@ -324,44 +324,47 @@ pub fn create_program_runtime_environment_v1<'a>( aligned_memory_mapping: !feature_set.is_active(&bpf_account_data_direct_mapping::id()), // Warning, do not use `Config::default()` so that configuration here is explicit. }; - let mut result = FunctionRegistry::>::default(); + let mut result = BuiltinProgram::new_loader_with_dense_registration(config); // Abort - result.register_function_hashed(*b"abort", SyscallAbort::vm)?; + result.register_function("abort", 1, SyscallAbort::vm)?; // Panic - result.register_function_hashed(*b"sol_panic_", SyscallPanic::vm)?; + result.register_function("sol_panic_", 2, SyscallPanic::vm)?; // Logging - result.register_function_hashed(*b"sol_log_", SyscallLog::vm)?; - result.register_function_hashed(*b"sol_log_64_", SyscallLogU64::vm)?; - result.register_function_hashed(*b"sol_log_compute_units_", SyscallLogBpfComputeUnits::vm)?; - result.register_function_hashed(*b"sol_log_pubkey", SyscallLogPubkey::vm)?; + result.register_function("sol_log_", 7, SyscallLog::vm)?; + result.register_function("sol_log_64_", 8, SyscallLogU64::vm)?; + result.register_function("sol_log_pubkey", 9, SyscallLogPubkey::vm)?; + result.register_function("sol_log_compute_units_", 10, SyscallLogBpfComputeUnits::vm)?; // Program defined addresses (PDA) - result.register_function_hashed( - *b"sol_create_program_address", + result.register_function( + "sol_create_program_address", + 32, SyscallCreateProgramAddress::vm, )?; - result.register_function_hashed( - *b"sol_try_find_program_address", + result.register_function( + "sol_try_find_program_address", + 33, SyscallTryFindProgramAddress::vm, )?; // Sha256 - result.register_function_hashed(*b"sol_sha256", SyscallHash::vm::)?; + result.register_function("sol_sha256", 17, SyscallHash::vm::)?; // Keccak256 - result.register_function_hashed(*b"sol_keccak256", SyscallHash::vm::)?; + result.register_function("sol_keccak256", 18, SyscallHash::vm::)?; // Secp256k1 Recover - result.register_function_hashed(*b"sol_secp256k1_recover", SyscallSecp256k1Recover::vm)?; + result.register_function("sol_secp256k1_recover", 19, SyscallSecp256k1Recover::vm)?; // Blake3 register_feature_gated_function!( result, blake3_syscall_enabled, - *b"sol_blake3", + "sol_blake3", + 20, SyscallHash::vm::, )?; @@ -369,78 +372,87 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, curve25519_syscall_enabled, - *b"sol_curve_validate_point", + "sol_curve_validate_point", + 24, SyscallCurvePointValidation::vm, )?; register_feature_gated_function!( result, curve25519_syscall_enabled, - *b"sol_curve_group_op", + "sol_curve_group_op", + 25, SyscallCurveGroupOps::vm, )?; register_feature_gated_function!( result, curve25519_syscall_enabled, - *b"sol_curve_multiscalar_mul", + "sol_curve_multiscalar_mul", + 26, SyscallCurveMultiscalarMultiplication::vm, )?; // Sysvars - result.register_function_hashed(*b"sol_get_clock_sysvar", SyscallGetClockSysvar::vm)?; - result.register_function_hashed( - *b"sol_get_epoch_schedule_sysvar", + result.register_function("sol_get_clock_sysvar", 36, SyscallGetClockSysvar::vm)?; + result.register_function( + "sol_get_epoch_schedule_sysvar", + 37, SyscallGetEpochScheduleSysvar::vm, )?; register_feature_gated_function!( result, !disable_fees_sysvar, - *b"sol_get_fees_sysvar", + "sol_get_fees_sysvar", + 40, SyscallGetFeesSysvar::vm, )?; - result.register_function_hashed(*b"sol_get_rent_sysvar", SyscallGetRentSysvar::vm)?; + result.register_function("sol_get_rent_sysvar", 41, SyscallGetRentSysvar::vm)?; register_feature_gated_function!( result, last_restart_slot_syscall_enabled, - *b"sol_get_last_restart_slot", + "sol_get_last_restart_slot", + 38, SyscallGetLastRestartSlotSysvar::vm, )?; register_feature_gated_function!( result, epoch_rewards_syscall_enabled, - *b"sol_get_epoch_rewards_sysvar", + "sol_get_epoch_rewards_sysvar", + 39, SyscallGetEpochRewardsSysvar::vm, )?; // Memory ops - result.register_function_hashed(*b"sol_memcpy_", SyscallMemcpy::vm)?; - result.register_function_hashed(*b"sol_memmove_", SyscallMemmove::vm)?; - result.register_function_hashed(*b"sol_memcmp_", SyscallMemcmp::vm)?; - result.register_function_hashed(*b"sol_memset_", SyscallMemset::vm)?; + result.register_function("sol_memcpy_", 3, SyscallMemcpy::vm)?; + result.register_function("sol_memmove_", 4, SyscallMemmove::vm)?; + result.register_function("sol_memset_", 5, SyscallMemset::vm)?; + result.register_function("sol_memcmp_", 6, SyscallMemcmp::vm)?; // Processed sibling instructions - result.register_function_hashed( - *b"sol_get_processed_sibling_instruction", + result.register_function( + "sol_get_processed_sibling_instruction", + 22, SyscallGetProcessedSiblingInstruction::vm, )?; // Stack height - result.register_function_hashed(*b"sol_get_stack_height", SyscallGetStackHeight::vm)?; + result.register_function("sol_get_stack_height", 23, SyscallGetStackHeight::vm)?; // Return data - result.register_function_hashed(*b"sol_set_return_data", SyscallSetReturnData::vm)?; - result.register_function_hashed(*b"sol_get_return_data", SyscallGetReturnData::vm)?; + result.register_function("sol_set_return_data", 14, SyscallSetReturnData::vm)?; + result.register_function("sol_get_return_data", 15, SyscallGetReturnData::vm)?; // Cross-program invocation - result.register_function_hashed(*b"sol_invoke_signed_c", SyscallInvokeSignedC::vm)?; - result.register_function_hashed(*b"sol_invoke_signed_rust", SyscallInvokeSignedRust::vm)?; + result.register_function("sol_invoke_signed_c", 12, SyscallInvokeSignedC::vm)?; + result.register_function("sol_invoke_signed_rust", 13, SyscallInvokeSignedRust::vm)?; // Memory allocator register_feature_gated_function!( result, !disable_deploy_of_alloc_free_syscall, - *b"sol_alloc_free_", + "sol_alloc_free_", + 11, SyscallAllocFree::vm, )?; @@ -448,7 +460,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, enable_alt_bn128_syscall, - *b"sol_alt_bn128_group_op", + "sol_alt_bn128_group_op", + 28, SyscallAltBn128::vm, )?; @@ -456,7 +469,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, enable_big_mod_exp_syscall, - *b"sol_big_mod_exp", + "sol_big_mod_exp", + 30, SyscallBigModExp::vm, )?; @@ -464,7 +478,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, enable_poseidon_syscall, - *b"sol_poseidon", + "sol_poseidon", + 21, SyscallPoseidon::vm, )?; @@ -472,7 +487,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, remaining_compute_units_syscall_enabled, - *b"sol_remaining_compute_units", + "sol_remaining_compute_units", + 31, SyscallRemainingComputeUnits::vm )?; @@ -480,7 +496,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, enable_alt_bn128_compression_syscall, - *b"sol_alt_bn128_compression", + "sol_alt_bn128_compression", + 29, SyscallAltBn128Compression::vm, )?; @@ -488,7 +505,8 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, get_sysvar_syscall_enabled, - *b"sol_get_sysvar", + "sol_get_sysvar", + 34, SyscallGetSysvar::vm, )?; @@ -496,14 +514,15 @@ pub fn create_program_runtime_environment_v1<'a>( register_feature_gated_function!( result, enable_get_epoch_stake_syscall, - *b"sol_get_epoch_stake", + "sol_get_epoch_stake", + 35, SyscallGetEpochStake::vm, )?; // Log data - result.register_function_hashed(*b"sol_log_data", SyscallLogData::vm)?; + result.register_function("sol_log_data", 16, SyscallLogData::vm)?; - Ok(BuiltinProgram::new_loader(config, result)) + Ok(result) } pub fn create_program_runtime_environment_v2<'a>( From 694235669538afce1a40bbad7208b3621ae61d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 16 Dec 2024 22:43:36 +0000 Subject: [PATCH 3/3] Review feedback --- program-runtime/src/invoke_context.rs | 2 +- programs/bpf_loader/src/syscalls/mod.rs | 1 + runtime/src/bank/tests.rs | 17 ++++++++--------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 6e47e2622a65fc..6f11dd058c592d 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -555,7 +555,7 @@ impl<'a> InvokeContext<'a> { // For now, only built-ins are invoked from here, so the VM and its Config are irrelevant. let mock_config = Config::default(); let empty_memory_mapping = - MemoryMapping::new(Vec::new(), &mock_config, SBPFVersion::V1).unwrap(); + MemoryMapping::new(Vec::new(), &mock_config, SBPFVersion::V0).unwrap(); let mut vm = EbpfVm::new( self.program_cache_for_tx_batch .environments diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 4281d43054fb88..c1f60fb67e2894 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -306,6 +306,7 @@ pub fn create_program_runtime_environment_v1<'a>( } else { SBPFVersion::V0 }; + debug_assert!(min_sbpf_version <= max_sbpf_version); let config = Config { max_call_depth: compute_budget.max_call_depth, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index a03674a2231424..2005cd5e23a4f1 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -12084,14 +12084,13 @@ fn test_feature_activation_loaded_programs_cache_preparation_phase() { solana_logger::setup(); // Bank Setup - let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); - genesis_config - .accounts - .remove(&feature_set::disable_sbpf_v0_execution::id()); - genesis_config - .accounts - .remove(&feature_set::reenable_sbpf_v0_execution::id()); - let (root_bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let (genesis_config, mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); + let mut bank = Bank::new_for_tests(&genesis_config); + let mut feature_set = FeatureSet::all_enabled(); + feature_set.deactivate(&feature_set::disable_sbpf_v0_execution::id()); + feature_set.deactivate(&feature_set::reenable_sbpf_v0_execution::id()); + bank.feature_set = Arc::new(feature_set); + let (root_bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); // Program Setup let program_keypair = Keypair::new(); @@ -12183,7 +12182,7 @@ fn test_feature_activation_loaded_programs_cache_preparation_phase() { result_with_feature_enabled, Err(TransactionError::InstructionError( 0, - InstructionError::InvalidAccountData + InstructionError::UnsupportedProgramId )) ); }