From a9c8f59747322b448f13c00e9873cbb11b948202 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] Bumps solana_rbpf to v0.9.0 --- Cargo.lock | 5 +- Cargo.toml | 2 +- program-runtime/src/invoke_context.rs | 6 +- programs/bpf_loader/src/lib.rs | 2 +- programs/bpf_loader/src/syscalls/cpi.rs | 24 ++-- programs/bpf_loader/src/syscalls/mem_ops.rs | 130 ++++++++++---------- programs/bpf_loader/src/syscalls/mod.rs | 123 +++++++++--------- programs/sbf/Cargo.lock | 5 +- programs/sbf/Cargo.toml | 2 +- runtime/src/bank/tests.rs | 8 +- sdk/feature-set/src/lib.rs | 23 +++- svm/examples/Cargo.lock | 5 +- 12 files changed, 180 insertions(+), 155 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2272c19754ba95..6276a69452a974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9641,9 +9641,8 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" +version = "0.8.2" +source = "git+https://github.com/solana-labs/rbpf.git#4ad935be45e5663be23b30cfc750b1ae1ad03c44" dependencies = [ "byteorder", "combine 3.8.1", diff --git a/Cargo.toml b/Cargo.toml index 55ce023631449f..a591114cd05487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -583,7 +583,7 @@ 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" +solana_rbpf = { git = "https://github.com/solana-labs/rbpf.git" } spl-associated-token-account = "=6.0.0" spl-instruction-padding = "0.3" spl-memo = "=6.0.0" diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index f6e0e4630a8d3f..0828d60b03e335 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -541,7 +541,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, @@ -560,13 +560,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/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 9f62c4f036f5ab..9cf02e7cac15d4 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -331,7 +331,7 @@ macro_rules! mock_create_vm { let executable = solana_rbpf::elf::Executable::::from_text_bytes( &[0x95, 0, 0, 0, 0, 0, 0, 0], loader, - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); diff --git a/programs/bpf_loader/src/syscalls/cpi.rs b/programs/bpf_loader/src/syscalls/cpi.rs index 6886723afe97e4..952deb6a2f2072 100644 --- a/programs/bpf_loader/src/syscalls/cpi.rs +++ b/programs/bpf_loader/src/syscalls/cpi.rs @@ -1711,7 +1711,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, @@ -1747,7 +1747,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, @@ -1783,7 +1783,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(); @@ -1833,7 +1833,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1891,7 +1891,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2019,7 +2019,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2194,7 +2194,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2264,7 +2264,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2320,7 +2320,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2393,7 +2393,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2481,7 +2481,7 @@ mod tests { let memory_mapping = MemoryMapping::new( mock_caller_account.regions.split_off(0), &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2559,7 +2559,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/mem_ops.rs b/programs/bpf_loader/src/syscalls/mem_ops.rs index 0367c03d006ad8..9b0338f0c1fa2f 100644 --- a/programs/bpf_loader/src/syscalls/mem_ops.rs +++ b/programs/bpf_loader/src/syscalls/mem_ops.rs @@ -515,7 +515,7 @@ mod tests { use { super::*, assert_matches::assert_matches, - solana_rbpf::{ebpf::MM_PROGRAM_START, program::SBPFVersion}, + solana_rbpf::{ebpf::MM_RODATA_START, program::SBPFVersion}, test_case::test_case, }; @@ -533,7 +533,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(); @@ -547,7 +547,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(); @@ -562,51 +562,51 @@ 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(); // check oob at the lower bound on the first next() let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_PROGRAM_START - 1, 42) + MemoryChunkIterator::new(&memory_mapping, AccessType::Load, 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() let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_PROGRAM_START - 1, 43) + MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_RODATA_START - 1, 43) .unwrap() .rev(); 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 ); } @@ -618,30 +618,30 @@ 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(); // check lower bound let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_PROGRAM_START - 1, 1) + MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_RODATA_START - 1, 1) .unwrap(); assert!(src_chunk_iter.next().unwrap().is_err()); // check upper bound let mut src_chunk_iter = - MemoryChunkIterator::new(&memory_mapping, AccessType::Load, MM_PROGRAM_START + 42, 1) + MemoryChunkIterator::new(&memory_mapping, AccessType::Load, 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 = @@ -671,22 +671,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 = @@ -714,11 +714,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(); @@ -726,30 +726,30 @@ 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 ); } @@ -764,15 +764,15 @@ 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, 4, &memory_mapping).unwrap(); + memmove_non_contiguous(MM_RODATA_START, MM_RODATA_START + 8, 4, &memory_mapping).unwrap(); } #[test_case(&[], (0, 0, 0); "no regions")] @@ -816,8 +816,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, ) @@ -841,16 +841,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 ); } @@ -867,18 +867,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]); @@ -898,18 +898,18 @@ 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, 9, &memory_mapping) + memcmp_non_contiguous(MM_RODATA_START, MM_RODATA_START + 9, 9, &memory_mapping) .unwrap(), 0 ); @@ -917,8 +917,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 ) @@ -929,8 +929,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 ) @@ -954,12 +954,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..a5acf8ad31b037 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -21,12 +21,13 @@ 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, @@ -35,7 +36,7 @@ use { solana_rbpf::{ declare_builtin_function, memory_region::{AccessType, MemoryMapping}, - program::{BuiltinFunction, BuiltinProgram, FunctionRegistry}, + program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion}, vm::Config, }, solana_sdk::{ @@ -244,12 +245,14 @@ 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; + 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 +287,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 +317,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 +520,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. @@ -2191,7 +2204,7 @@ mod tests { let memory_mapping = MemoryMapping::new( vec![MemoryRegion::new_readonly(&data, START)], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2232,7 +2245,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 +2261,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 +2283,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 +2296,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 +2321,7 @@ mod tests { 0x100000000, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2328,7 +2341,7 @@ mod tests { 0x100000000, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); let translated_data = @@ -2346,7 +2359,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 +2383,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 +2398,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 +2439,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 +2506,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 +2530,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 +2713,7 @@ mod tests { MemoryRegion::new_readonly(bytes2.as_bytes(), bytes_to_hash[1].vm_addr), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2798,7 +2811,7 @@ mod tests { MemoryRegion::new_readonly(&invalid_bytes, invalid_bytes_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2871,7 +2884,7 @@ mod tests { MemoryRegion::new_readonly(&invalid_bytes, invalid_bytes_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -2958,7 +2971,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3113,7 +3126,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3283,7 +3296,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3376,7 +3389,7 @@ mod tests { MemoryRegion::new_writable(bytes_of_slice_mut(&mut result_point), result_point_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3561,7 +3574,7 @@ mod tests { MemoryRegion::new_readonly(&Clock::id().to_bytes(), clock_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3627,7 +3640,7 @@ mod tests { ), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3689,7 +3702,7 @@ mod tests { got_fees_va, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3728,7 +3741,7 @@ mod tests { MemoryRegion::new_readonly(&Rent::id().to_bytes(), rent_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3788,7 +3801,7 @@ mod tests { MemoryRegion::new_readonly(&EpochRewards::id().to_bytes(), rewards_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3853,7 +3866,7 @@ mod tests { MemoryRegion::new_readonly(&LastRestartSlot::id().to_bytes(), restart_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3938,7 +3951,7 @@ mod tests { MemoryRegion::new_readonly(&StakeHistory::id().to_bytes(), history_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -3997,7 +4010,7 @@ mod tests { MemoryRegion::new_readonly(&SlotHashes::id().to_bytes(), hashes_id_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4043,7 +4056,7 @@ mod tests { MemoryRegion::new_readonly(&got_clock_buf_ro, got_clock_buf_ro_va), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4232,7 +4245,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 +4309,7 @@ mod tests { MemoryRegion::new_writable(&mut id_buffer, PROGRAM_ID_VA), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4396,7 +4409,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 +4715,7 @@ mod tests { MemoryRegion::new_writable(&mut data_out, VADDR_OUT), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4744,7 +4757,7 @@ mod tests { MemoryRegion::new_writable(&mut data_out, VADDR_OUT), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4799,7 +4812,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 +4876,7 @@ mod tests { MemoryRegion::new_readonly(&[2; 31], vote_address_var), ], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4893,7 +4906,7 @@ mod tests { vote_address_var, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -4925,7 +4938,7 @@ mod tests { vote_address_var, )], &config, - &SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 56d19a39df423c..360cf6237d6387 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -8033,9 +8033,8 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" +version = "0.8.2" +source = "git+https://github.com/solana-labs/rbpf.git#4ad935be45e5663be23b30cfc750b1ae1ad03c44" dependencies = [ "byteorder 1.5.0", "combine 3.8.1", diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 7d48d1ab8efca2..e926cfbce17f99 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -68,7 +68,7 @@ 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" +solana_rbpf = { git = "https://github.com/solana-labs/rbpf.git" } thiserror = "1.0" [package] diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 5e29644cf17d11..f66734e598aa6e 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -12016,10 +12016,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 @@ -12053,7 +12053,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), ); @@ -12128,7 +12128,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 6725f02212b425..e48a95b36379d2 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"); } @@ -1102,8 +1114,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/examples/Cargo.lock b/svm/examples/Cargo.lock index 25731aa1f24f83..a78dd297c03d1d 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -7385,9 +7385,8 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1941b5ef0c3ce8f2ac5dd984d0fb1a97423c4ff2a02eec81e3913f02e2ac2b" +version = "0.8.2" +source = "git+https://github.com/solana-labs/rbpf.git#4ad935be45e5663be23b30cfc750b1ae1ad03c44" dependencies = [ "byteorder", "combine 3.8.1",