From bbd8be6cbe9bd22bb4273f7bdc44b9d613a3a981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 11 May 2023 08:29:06 +0200 Subject: [PATCH] Refactor - Renames loader-v3 to loader-v4. (#31570) Renames loader-v3 to loader-v4. --- Cargo.lock | 4 +- Cargo.toml | 4 +- program-runtime/src/loaded_programs.rs | 4 +- programs/{loader-v3 => loader-v4}/Cargo.toml | 4 +- programs/{loader-v3 => loader-v4}/src/lib.rs | 172 +++++++++--------- .../test_elfs/out/invalid.so | Bin .../test_elfs/out/noop.so | Bin .../test_elfs/out/rodata.so | Bin programs/sbf/Cargo.lock | 4 +- runtime/Cargo.toml | 2 +- runtime/src/bank.rs | 6 +- sdk/program/src/lib.rs | 4 +- .../src/{loader_v3.rs => loader_v4.rs} | 8 +- ...nstruction.rs => loader_v4_instruction.rs} | 2 +- sdk/src/lib.rs | 4 +- 15 files changed, 109 insertions(+), 109 deletions(-) rename programs/{loader-v3 => loader-v4}/Cargo.toml (90%) rename programs/{loader-v3 => loader-v4}/src/lib.rs (90%) rename programs/{loader-v3 => loader-v4}/test_elfs/out/invalid.so (100%) rename programs/{loader-v3 => loader-v4}/test_elfs/out/noop.so (100%) rename programs/{loader-v3 => loader-v4}/test_elfs/out/rodata.so (100%) rename sdk/program/src/{loader_v3.rs => loader_v4.rs} (86%) rename sdk/program/src/{loader_v3_instruction.rs => loader_v4_instruction.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index 85bdec3f358d7e..43da9621ab3907 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6037,7 +6037,7 @@ dependencies = [ ] [[package]] -name = "solana-loader-v3-program" +name = "solana-loader-v4-program" version = "1.16.0" dependencies = [ "bincode", @@ -6716,7 +6716,7 @@ dependencies = [ "solana-config-program", "solana-frozen-abi 1.16.0", "solana-frozen-abi-macro 1.16.0", - "solana-loader-v3-program", + "solana-loader-v4-program", "solana-logger 1.16.0", "solana-measure", "solana-metrics", diff --git a/Cargo.toml b/Cargo.toml index 1bb81398de8c08..e40beab95fcc79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ members = [ "programs/compute-budget", "programs/config", "programs/ed25519-tests", - "programs/loader-v3", + "programs/loader-v4", "programs/stake", "programs/system", "programs/vote", @@ -319,7 +319,7 @@ solana-genesis-utils = { path = "genesis-utils", version = "=1.16.0" } solana-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=1.16.0" } solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=1.16.0" } solana-gossip = { path = "gossip", version = "=1.16.0" } -solana-loader-v3-program = { path = "programs/loader-v3", version = "=1.16.0" } +solana-loader-v4-program = { path = "programs/loader-v4", version = "=1.16.0" } solana-ledger = { path = "ledger", version = "=1.16.0" } solana-local-cluster = { path = "local-cluster", version = "=1.16.0" } solana-logger = { path = "logger", version = "=1.16.0" } diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 8392b6012e5f09..045a1baf357789 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -12,7 +12,7 @@ use { vm::{BuiltInProgram, VerifiedExecutable}, }, solana_sdk::{ - bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::Slot, loader_v3, + bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::Slot, loader_v4, pubkey::Pubkey, saturating_add_assign, }, std::{ @@ -228,7 +228,7 @@ impl LoadedProgram { LoadedProgramType::LegacyV0(VerifiedExecutable::from_executable(executable)?) } else if bpf_loader::check_id(loader_key) || bpf_loader_upgradeable::check_id(loader_key) { LoadedProgramType::LegacyV1(VerifiedExecutable::from_executable(executable)?) - } else if loader_v3::check_id(loader_key) { + } else if loader_v4::check_id(loader_key) { LoadedProgramType::Typed(VerifiedExecutable::from_executable(executable)?) } else { panic!(); diff --git a/programs/loader-v3/Cargo.toml b/programs/loader-v4/Cargo.toml similarity index 90% rename from programs/loader-v3/Cargo.toml rename to programs/loader-v4/Cargo.toml index b844c41590f51a..8580b5c77f27e3 100644 --- a/programs/loader-v3/Cargo.toml +++ b/programs/loader-v4/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "solana-loader-v3-program" +name = "solana-loader-v4-program" description = "Solana Loader v3" publish = false version = { workspace = true } @@ -22,7 +22,7 @@ bincode = { workspace = true } [lib] crate-type = ["lib"] -name = "solana_loader_v3_program" +name = "solana_loader_v4_program" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/programs/loader-v3/src/lib.rs b/programs/loader-v4/src/lib.rs similarity index 90% rename from programs/loader-v3/src/lib.rs rename to programs/loader-v4/src/lib.rs index 1af418235fea47..cb6cfb28a23e46 100644 --- a/programs/loader-v3/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -23,8 +23,8 @@ use { entrypoint::{HEAP_LENGTH, SUCCESS}, feature_set::{self, FeatureSet}, instruction::InstructionError, - loader_v3::{self, LoaderV3State, DEPLOYMENT_COOLDOWN_IN_SLOTS}, - loader_v3_instruction::LoaderV3Instruction, + loader_v4::{self, LoaderV4State, DEPLOYMENT_COOLDOWN_IN_SLOTS}, + loader_v4_instruction::LoaderV4Instruction, program_utils::limited_deserialize, pubkey::Pubkey, saturating_add_assign, @@ -37,30 +37,30 @@ use { }, }; -pub fn get_state(data: &[u8]) -> Result<&LoaderV3State, InstructionError> { +pub fn get_state(data: &[u8]) -> Result<&LoaderV4State, InstructionError> { unsafe { let data = data - .get(0..LoaderV3State::program_data_offset()) + .get(0..LoaderV4State::program_data_offset()) .ok_or(InstructionError::AccountDataTooSmall)? .try_into() .unwrap(); Ok(std::mem::transmute::< - &[u8; LoaderV3State::program_data_offset()], - &LoaderV3State, + &[u8; LoaderV4State::program_data_offset()], + &LoaderV4State, >(data)) } } -fn get_state_mut(data: &mut [u8]) -> Result<&mut LoaderV3State, InstructionError> { +fn get_state_mut(data: &mut [u8]) -> Result<&mut LoaderV4State, InstructionError> { unsafe { let data = data - .get_mut(0..LoaderV3State::program_data_offset()) + .get_mut(0..LoaderV4State::program_data_offset()) .ok_or(InstructionError::AccountDataTooSmall)? .try_into() .unwrap(); Ok(std::mem::transmute::< - &mut [u8; LoaderV3State::program_data_offset()], - &mut LoaderV3State, + &mut [u8; LoaderV4State::program_data_offset()], + &mut LoaderV4State, >(data)) } } @@ -107,10 +107,10 @@ pub fn load_program_from_account( let state = get_state(program.get_data())?; let programdata = program .get_data() - .get(LoaderV3State::program_data_offset()..) + .get(LoaderV4State::program_data_offset()..) .ok_or(InstructionError::AccountDataTooSmall)?; let loaded_program = LoadedProgram::new( - &loader_v3::id(), + &loader_v4::id(), Arc::new(loader), state.slot, state.slot.saturating_add(1), @@ -227,8 +227,8 @@ fn check_program_account( instruction_context: &InstructionContext, program: &BorrowedAccount, authority_address: &Pubkey, -) -> Result { - if !loader_v3::check_id(program.get_owner()) { +) -> Result { + if !loader_v4::check_id(program.get_owner()) { ic_logger_msg!(log_collector, "Program not owned by loader"); return Err(InstructionError::InvalidAccountOwner); } @@ -273,7 +273,7 @@ pub fn process_instruction_write( .ok(); let is_initialization = offset == 0 && program.get_data().is_empty(); if is_initialization { - if !loader_v3::check_id(program.get_owner()) { + if !loader_v4::check_id(program.get_owner()) { ic_logger_msg!(log_collector, "Program not owned by loader"); return Err(InstructionError::InvalidAccountOwner); } @@ -308,7 +308,7 @@ pub fn process_instruction_write( let program_size = program .get_data() .len() - .saturating_sub(LoaderV3State::program_data_offset()); + .saturating_sub(LoaderV4State::program_data_offset()); if offset as usize > program_size { ic_logger_msg!(log_collector, "Write out of bounds"); return Err(InstructionError::AccountDataTooSmall); @@ -316,7 +316,7 @@ pub fn process_instruction_write( let end_offset = (offset as usize).saturating_add(bytes.len()); let rent = invoke_context.get_sysvar_cache().get_rent()?; let required_lamports = - rent.minimum_balance(LoaderV3State::program_data_offset().saturating_add(end_offset)); + rent.minimum_balance(LoaderV4State::program_data_offset().saturating_add(end_offset)); let transfer_lamports = required_lamports.saturating_sub(program.get_lamports()); if transfer_lamports > 0 { payer = payer.filter(|payer| payer.get_lamports() >= transfer_lamports); @@ -330,7 +330,7 @@ pub fn process_instruction_write( } } if end_offset > program_size { - program.set_data_length(LoaderV3State::program_data_offset().saturating_add(end_offset))?; + program.set_data_length(LoaderV4State::program_data_offset().saturating_add(end_offset))?; } if let Some(mut payer) = payer { payer.checked_sub_lamports(transfer_lamports)?; @@ -345,8 +345,8 @@ pub fn process_instruction_write( program .get_data_mut()? .get_mut( - LoaderV3State::program_data_offset().saturating_add(offset as usize) - ..LoaderV3State::program_data_offset().saturating_add(end_offset), + LoaderV4State::program_data_offset().saturating_add(offset as usize) + ..LoaderV4State::program_data_offset().saturating_add(end_offset), ) .ok_or(InstructionError::AccountDataTooSmall)? .copy_from_slice(&bytes); @@ -379,7 +379,7 @@ pub fn process_instruction_truncate( let program_size = program .get_data() .len() - .saturating_sub(LoaderV3State::program_data_offset()); + .saturating_sub(LoaderV4State::program_data_offset()); if offset as usize > program_size { ic_logger_msg!(log_collector, "Truncate out of bounds"); return Err(InstructionError::AccountDataTooSmall); @@ -389,7 +389,7 @@ pub fn process_instruction_truncate( 0 } else { program.set_data_length( - LoaderV3State::program_data_offset().saturating_add(offset as usize), + LoaderV4State::program_data_offset().saturating_add(offset as usize), )?; let rent = invoke_context.get_sysvar_cache().get_rent()?; rent.minimum_balance(program.get_data().len()) @@ -553,7 +553,7 @@ pub fn process_instruction_inner( let instruction_context = transaction_context.get_current_instruction_context()?; let instruction_data = instruction_context.get_instruction_data(); let program_id = instruction_context.get_last_program_key(transaction_context)?; - if loader_v3::check_id(program_id) { + if loader_v4::check_id(program_id) { if invoke_context .feature_set .is_active(&feature_set::native_programs_consume_cu::id()) @@ -561,22 +561,22 @@ pub fn process_instruction_inner( invoke_context.consume_checked(2000)?; } match limited_deserialize(instruction_data)? { - LoaderV3Instruction::Write { offset, bytes } => { + LoaderV4Instruction::Write { offset, bytes } => { process_instruction_write(invoke_context, offset, bytes) } - LoaderV3Instruction::Truncate { offset } => { + LoaderV4Instruction::Truncate { offset } => { process_instruction_truncate(invoke_context, offset) } - LoaderV3Instruction::Deploy => process_instruction_deploy(invoke_context), - LoaderV3Instruction::Retract => process_instruction_retract(invoke_context), - LoaderV3Instruction::TransferAuthority => { + LoaderV4Instruction::Deploy => process_instruction_deploy(invoke_context), + LoaderV4Instruction::Retract => process_instruction_retract(invoke_context), + LoaderV4Instruction::TransferAuthority => { process_instruction_transfer_authority(invoke_context) } } .map_err(|err| Box::new(err) as Box) } else { let program = instruction_context.try_borrow_last_program_account(transaction_context)?; - if !loader_v3::check_id(program.get_owner()) { + if !loader_v4::check_id(program.get_owner()) { ic_logger_msg!(log_collector, "Program not owned by loader"); return Err(Box::new(InstructionError::InvalidAccountOwner)); } @@ -655,7 +655,7 @@ mod tests { ) .collect::>(); mock_process_instruction( - &loader_v3::id(), + &loader_v4::id(), program_indices, instruction_data, transaction_accounts, @@ -678,20 +678,20 @@ mod tests { file.read_to_end(&mut elf_bytes).unwrap(); let rent = rent::Rent::default(); let account_size = - loader_v3::LoaderV3State::program_data_offset().saturating_add(elf_bytes.len()); + loader_v4::LoaderV4State::program_data_offset().saturating_add(elf_bytes.len()); let mut program_account = AccountSharedData::new( rent.minimum_balance(account_size), account_size, - &loader_v3::id(), + &loader_v4::id(), ); program_account - .set_state(&loader_v3::LoaderV3State { + .set_state(&loader_v4::LoaderV4State { slot: 0, is_deployed, authority_address, }) .unwrap(); - program_account.data_as_mut_slice()[loader_v3::LoaderV3State::program_data_offset()..] + program_account.data_as_mut_slice()[loader_v4::LoaderV4State::program_data_offset()..] .copy_from_slice(&elf_bytes); program_account } @@ -704,7 +704,7 @@ mod tests { create_account_shared_data_for_test(&clock) } - fn test_loader_instruction_general_errors(instruction: LoaderV3Instruction) { + fn test_loader_instruction_general_errors(instruction: LoaderV4Instruction) { let instruction = bincode::serialize(&instruction).unwrap(); let authority_address = Pubkey::new_unique(); let transaction_accounts = vec![ @@ -800,7 +800,7 @@ mod tests { let mut transaction_accounts = vec![ ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( authority_address, @@ -808,7 +808,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(10000000, 0, &loader_v3::id()), + AccountSharedData::new(10000000, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), @@ -827,7 +827,7 @@ mod tests { // Initialize account by first write let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 0, bytes: vec![0, 1, 2, 3], }) @@ -838,7 +838,7 @@ mod tests { ); assert_eq!( accounts[0].data().len(), - loader_v3::LoaderV3State::program_data_offset().saturating_add(4), + loader_v4::LoaderV4State::program_data_offset().saturating_add(4), ); assert_eq!(accounts[0].lamports(), 1252800); assert_eq!( @@ -852,7 +852,7 @@ mod tests { // Error: Program is not writeable process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 0, bytes: vec![0, 1, 2, 3], }) @@ -865,7 +865,7 @@ mod tests { // Error: Authority did not sign process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 0, bytes: vec![0, 1, 2, 3], }) @@ -879,7 +879,7 @@ mod tests { transaction_accounts[0].1 = accounts[0].clone(); let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 4, bytes: vec![4, 5, 6, 7], }) @@ -890,7 +890,7 @@ mod tests { ); assert_eq!( accounts[0].data().len(), - loader_v3::LoaderV3State::program_data_offset().saturating_add(8), + loader_v4::LoaderV4State::program_data_offset().saturating_add(8), ); assert_eq!( accounts[0].lamports(), @@ -909,7 +909,7 @@ mod tests { transaction_accounts[0].1 = accounts[0].clone(); let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 2, bytes: vec![8, 8, 8, 8], }) @@ -920,7 +920,7 @@ mod tests { ); assert_eq!( accounts[0].data().len(), - loader_v3::LoaderV3State::program_data_offset().saturating_add(8), + loader_v4::LoaderV4State::program_data_offset().saturating_add(8), ); assert_eq!(accounts[0].lamports(), transaction_accounts[0].1.lamports()); @@ -928,7 +928,7 @@ mod tests { transaction_accounts[0].1 = accounts[0].clone(); let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 2, bytes: Vec::new(), }) @@ -939,14 +939,14 @@ mod tests { ); assert_eq!( accounts[0].data().len(), - loader_v3::LoaderV3State::program_data_offset().saturating_add(8), + loader_v4::LoaderV4State::program_data_offset().saturating_add(8), ); assert_eq!(accounts[0].lamports(), transaction_accounts[0].1.lamports()); // Error: Program is not retracted process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 8, bytes: vec![8, 8, 8, 8], }) @@ -959,7 +959,7 @@ mod tests { // Error: Payer did not sign process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 8, bytes: vec![8, 8, 8, 8], }) @@ -972,7 +972,7 @@ mod tests { // Error: Payer is not writeable process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 8, bytes: vec![8, 8, 8, 8], }) @@ -985,7 +985,7 @@ mod tests { // Error: Write out of bounds process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 9, bytes: vec![8, 8, 8, 8], }) @@ -998,7 +998,7 @@ mod tests { // Error: Insufficient funds (Bankrupt payer account) process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 8, bytes: vec![8, 8, 8, 8], }) @@ -1011,7 +1011,7 @@ mod tests { // Error: Insufficient funds (No payer account) process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Write { + &bincode::serialize(&LoaderV4Instruction::Write { offset: 8, bytes: vec![8, 8, 8, 8], }) @@ -1021,7 +1021,7 @@ mod tests { Err(InstructionError::InsufficientFunds), ); - test_loader_instruction_general_errors(LoaderV3Instruction::Write { + test_loader_instruction_general_errors(LoaderV4Instruction::Write { offset: 0, bytes: Vec::new(), }); @@ -1041,7 +1041,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), @@ -1060,14 +1060,14 @@ mod tests { // Cut the end off let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Truncate { offset: 4 }).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Truncate { offset: 4 }).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false), (2, false, true)], Ok(()), ); assert_eq!( accounts[0].data().len(), - loader_v3::LoaderV3State::program_data_offset().saturating_add(4), + loader_v4::LoaderV4State::program_data_offset().saturating_add(4), ); assert_eq!(accounts[0].lamports(), 1252800); assert_eq!( @@ -1081,7 +1081,7 @@ mod tests { // Close program account let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Truncate { offset: 0 }).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Truncate { offset: 0 }).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false), (2, false, true)], Ok(()), @@ -1098,7 +1098,7 @@ mod tests { // Error: Program is uninitialized process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Truncate { offset: 0 }).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Truncate { offset: 0 }).unwrap(), transaction_accounts.clone(), &[(2, false, true), (1, true, false), (0, false, true)], Err(InstructionError::InvalidAccountData), @@ -1107,7 +1107,7 @@ mod tests { // Error: Program is not retracted process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Truncate { offset: 0 }).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Truncate { offset: 0 }).unwrap(), transaction_accounts.clone(), &[(3, false, true), (1, true, false), (2, false, true)], Err(InstructionError::InvalidArgument), @@ -1116,13 +1116,13 @@ mod tests { // Error: Truncate out of bounds process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Truncate { offset: 10000 }).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Truncate { offset: 10000 }).unwrap(), transaction_accounts, &[(0, false, true), (1, true, false), (2, false, true)], Err(InstructionError::AccountDataTooSmall), ); - test_loader_instruction_general_errors(LoaderV3Instruction::Truncate { offset: 0 }); + test_loader_instruction_general_errors(LoaderV4Instruction::Truncate { offset: 0 }); } #[test] @@ -1143,7 +1143,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), @@ -1159,7 +1159,7 @@ mod tests { // Deploy from its own data let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Ok(()), @@ -1175,7 +1175,7 @@ mod tests { // Error: Source program is not writable process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false), (2, false, false)], Err(InstructionError::InvalidArgument), @@ -1184,7 +1184,7 @@ mod tests { // Error: Source program is not retracted process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(2, false, true), (1, true, false), (0, false, true)], Err(InstructionError::InvalidArgument), @@ -1193,7 +1193,7 @@ mod tests { // Redeploy: Retract, then replace data by other source let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Retract).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Retract).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Ok(()), @@ -1201,7 +1201,7 @@ mod tests { transaction_accounts[0].1 = accounts[0].clone(); let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false), (2, false, true)], Ok(()), @@ -1224,7 +1224,7 @@ mod tests { // Error: Program was deployed recently, cooldown still in effect process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Err(InstructionError::InvalidArgument), @@ -1234,7 +1234,7 @@ mod tests { // Error: Program is uninitialized process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(3, false, true), (1, true, false)], Err(InstructionError::InvalidAccountData), @@ -1243,7 +1243,7 @@ mod tests { // Error: Program fails verification process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(4, false, true), (1, true, false)], Err(InstructionError::InvalidAccountData), @@ -1252,13 +1252,13 @@ mod tests { // Error: Program is deployed already process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Deploy).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Deploy).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Err(InstructionError::InvalidArgument), ); - test_loader_instruction_general_errors(LoaderV3Instruction::Deploy); + test_loader_instruction_general_errors(LoaderV4Instruction::Deploy); } #[test] @@ -1275,7 +1275,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), @@ -1291,7 +1291,7 @@ mod tests { // Retract program let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Retract).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Retract).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Ok(()), @@ -1305,7 +1305,7 @@ mod tests { // Error: Program is uninitialized process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Retract).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Retract).unwrap(), transaction_accounts.clone(), &[(2, false, true), (1, true, false)], Err(InstructionError::InvalidAccountData), @@ -1314,7 +1314,7 @@ mod tests { // Error: Program is not deployed process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Retract).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Retract).unwrap(), transaction_accounts.clone(), &[(3, false, true), (1, true, false)], Err(InstructionError::InvalidArgument), @@ -1324,13 +1324,13 @@ mod tests { transaction_accounts[4].1 = clock(0); process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::Retract).unwrap(), + &bincode::serialize(&LoaderV4Instruction::Retract).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Err(InstructionError::InvalidArgument), ); - test_loader_instruction_general_errors(LoaderV3Instruction::Retract); + test_loader_instruction_general_errors(LoaderV4Instruction::Retract); } #[test] @@ -1351,7 +1351,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( clock::id(), @@ -1366,7 +1366,7 @@ mod tests { // Transfer authority let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::TransferAuthority).unwrap(), + &bincode::serialize(&LoaderV4Instruction::TransferAuthority).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false), (2, true, false)], Ok(()), @@ -1380,7 +1380,7 @@ mod tests { // Finalize program let accounts = process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::TransferAuthority).unwrap(), + &bincode::serialize(&LoaderV4Instruction::TransferAuthority).unwrap(), transaction_accounts.clone(), &[(0, false, true), (1, true, false)], Ok(()), @@ -1394,7 +1394,7 @@ mod tests { // Error: Program is uninitialized process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::TransferAuthority).unwrap(), + &bincode::serialize(&LoaderV4Instruction::TransferAuthority).unwrap(), transaction_accounts.clone(), &[(3, false, true), (1, true, false), (2, true, false)], Err(InstructionError::InvalidAccountData), @@ -1403,13 +1403,13 @@ mod tests { // Error: New authority did not sign process_instruction( vec![], - &bincode::serialize(&LoaderV3Instruction::TransferAuthority).unwrap(), + &bincode::serialize(&LoaderV4Instruction::TransferAuthority).unwrap(), transaction_accounts, &[(0, false, true), (1, true, false), (2, false, false)], Err(InstructionError::MissingRequiredSignature), ); - test_loader_instruction_general_errors(LoaderV3Instruction::TransferAuthority); + test_loader_instruction_general_errors(LoaderV4Instruction::TransferAuthority); } #[test] @@ -1426,7 +1426,7 @@ mod tests { ), ( Pubkey::new_unique(), - AccountSharedData::new(0, 0, &loader_v3::id()), + AccountSharedData::new(0, 0, &loader_v4::id()), ), ( Pubkey::new_unique(), diff --git a/programs/loader-v3/test_elfs/out/invalid.so b/programs/loader-v4/test_elfs/out/invalid.so similarity index 100% rename from programs/loader-v3/test_elfs/out/invalid.so rename to programs/loader-v4/test_elfs/out/invalid.so diff --git a/programs/loader-v3/test_elfs/out/noop.so b/programs/loader-v4/test_elfs/out/noop.so similarity index 100% rename from programs/loader-v3/test_elfs/out/noop.so rename to programs/loader-v4/test_elfs/out/noop.so diff --git a/programs/loader-v3/test_elfs/out/rodata.so b/programs/loader-v4/test_elfs/out/rodata.so similarity index 100% rename from programs/loader-v3/test_elfs/out/rodata.so rename to programs/loader-v4/test_elfs/out/rodata.so diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 1f2044b6f7e5b8..ed6de4debf3fe5 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5125,7 +5125,7 @@ dependencies = [ ] [[package]] -name = "solana-loader-v3-program" +name = "solana-loader-v4-program" version = "1.16.0" dependencies = [ "log", @@ -5632,7 +5632,7 @@ dependencies = [ "solana-config-program", "solana-frozen-abi 1.16.0", "solana-frozen-abi-macro 1.16.0", - "solana-loader-v3-program", + "solana-loader-v4-program", "solana-measure", "solana-metrics", "solana-perf", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 003bf38300ad77..de1e86cf053332 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -50,7 +50,7 @@ solana-compute-budget-program = { workspace = true } solana-config-program = { workspace = true } solana-frozen-abi = { workspace = true } solana-frozen-abi-macro = { workspace = true } -solana-loader-v3-program = { workspace = true } +solana-loader-v4-program = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } solana-perf = { workspace = true } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e6242b3486b719..3ec275db259de3 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -137,7 +137,7 @@ use { inflation::Inflation, instruction::{CompiledInstruction, TRANSACTION_LEVEL_STACK_HEIGHT}, lamports::LamportsError, - loader_v3, + loader_v4, message::{AccountKeys, SanitizedMessage}, native_loader, native_token::{sol_to_lamports, LAMPORTS_PER_SOL}, @@ -4088,8 +4088,8 @@ impl Bank { } } Err(TransactionError::ProgramAccountNotFound) - } else if loader_v3::check_id(program.owner()) { - let state = solana_loader_v3_program::get_state(program.data()) + } else if loader_v4::check_id(program.owner()) { + let state = solana_loader_v4_program::get_state(program.data()) .map_err(|_| TransactionError::ProgramAccountNotFound)?; Ok(state.slot) } else { diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 69d9dfbd599178..98a767cf2eb025 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -500,8 +500,8 @@ pub mod keccak; pub mod lamports; pub mod loader_instruction; pub mod loader_upgradeable_instruction; -pub mod loader_v3; -pub mod loader_v3_instruction; +pub mod loader_v4; +pub mod loader_v4_instruction; pub mod log; pub mod message; pub mod native_token; diff --git a/sdk/program/src/loader_v3.rs b/sdk/program/src/loader_v4.rs similarity index 86% rename from sdk/program/src/loader_v3.rs rename to sdk/program/src/loader_v4.rs index 20331825efb1e1..3c1bd73a8202d0 100644 --- a/sdk/program/src/loader_v3.rs +++ b/sdk/program/src/loader_v4.rs @@ -4,15 +4,15 @@ use crate::pubkey::Pubkey; -crate::declare_id!("LoaderV311111111111111111111111111111111111"); +crate::declare_id!("LoaderV411111111111111111111111111111111111"); /// Cooldown before a program can be un-/redeployed again pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 750; -/// LoaderV3 account states +/// LoaderV4 account states #[repr(C)] #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy, AbiExample)] -pub struct LoaderV3State { +pub struct LoaderV4State { /// Slot that the program was last initialized, deployed or retracted in. pub slot: u64, /// True if the program is ready to be executed, false if it is retracted for maintainance. @@ -23,7 +23,7 @@ pub struct LoaderV3State { // account's data. } -impl LoaderV3State { +impl LoaderV4State { /// Size of a serialized program account. pub const fn program_data_offset() -> usize { std::mem::size_of::() diff --git a/sdk/program/src/loader_v3_instruction.rs b/sdk/program/src/loader_v4_instruction.rs similarity index 99% rename from sdk/program/src/loader_v3_instruction.rs rename to sdk/program/src/loader_v4_instruction.rs index 6b8dcc7faf4b69..38d6f87a25f5e1 100644 --- a/sdk/program/src/loader_v3_instruction.rs +++ b/sdk/program/src/loader_v4_instruction.rs @@ -2,7 +2,7 @@ #[repr(u8)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] -pub enum LoaderV3Instruction { +pub enum LoaderV4Instruction { /// Write ELF data into an undeployed program account. /// /// Writing at the end (offset is length) increases the size of the program account and diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index acea5822b7a85b..fa89d41cdede81 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -47,8 +47,8 @@ pub use solana_program::{ bpf_loader_deprecated, bpf_loader_upgradeable, clock, config, custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id, declare_sysvar_id, decode_error, ed25519_program, epoch_schedule, fee_calculator, impl_sysvar_get, incinerator, - instruction, keccak, lamports, loader_instruction, loader_upgradeable_instruction, loader_v3, - loader_v3_instruction, message, msg, native_token, nonce, program, program_error, + instruction, keccak, lamports, loader_instruction, loader_upgradeable_instruction, loader_v4, + loader_v4_instruction, message, msg, native_token, nonce, program, program_error, program_memory, program_option, program_pack, rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover, serde_varint, serialize_utils, short_vec, slot_hashes, slot_history, stable_layout, stake, stake_history, syscalls, system_instruction, system_program, sysvar,