Skip to content

Commit 64e19be

Browse files
authored
Fix - Loader-v3 to v4 migration of closed programs (#6106)
* Rekeys the feature enable_loader_v4. * Have closed programs be deleted by the rent collector instead of assigning them to the system program. * Allows uninitialized program accounts to be closed.
1 parent 3a26b6a commit 64e19be

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

feature-set/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ pub mod remaining_compute_units_syscall_enabled {
819819
}
820820

821821
pub mod enable_loader_v4 {
822-
solana_pubkey::declare_id!("G8yMNsNUd4p3VB22ycrPEB1qRgepCFeFpAqD2Lr66s36");
822+
solana_pubkey::declare_id!("2aQJYqER2aKyb3cZw22v4SL2xMX7vwXBRWfvS4pTrtED");
823823
}
824824

825825
pub mod require_rent_exempt_split_destination {

programs/bpf_loader/src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use {
3939
},
4040
solana_sdk_ids::{
4141
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4, native_loader,
42-
system_program,
4342
},
4443
solana_system_interface::{instruction as system_instruction, MAX_PERMITTED_DATA_LENGTH},
4544
solana_transaction_context::{IndexOfAccount, InstructionContext, TransactionContext},
@@ -1400,19 +1399,26 @@ fn process_loader_upgradeable_instruction(
14001399
}
14011400
program.set_data_from_slice(&[])?;
14021401
program.checked_add_lamports(programdata_funds)?;
1403-
if program_len == 0 {
1404-
program.set_owner(&system_program::id().to_bytes())?;
1405-
} else {
1406-
program.set_owner(&loader_v4::id().to_bytes())?;
1407-
}
1402+
program.set_owner(&loader_v4::id().to_bytes())?;
14081403
drop(program);
14091404

14101405
let mut programdata =
14111406
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
14121407
programdata.set_lamports(0)?;
14131408
drop(programdata);
14141409

1415-
if program_len > 0 {
1410+
if program_len == 0 {
1411+
invoke_context
1412+
.program_cache_for_tx_batch
1413+
.store_modified_entry(
1414+
program_address,
1415+
Arc::new(ProgramCacheEntry::new_tombstone(
1416+
clock_slot,
1417+
ProgramCacheEntryOwner::LoaderV4,
1418+
ProgramCacheEntryType::Closed,
1419+
)),
1420+
);
1421+
} else {
14161422
invoke_context.native_invoke(
14171423
solana_loader_v4_interface::instruction::set_program_length(
14181424
&program_address,
@@ -1474,7 +1480,6 @@ fn process_loader_upgradeable_instruction(
14741480
let mut programdata =
14751481
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
14761482
programdata.set_data_from_slice(&[])?;
1477-
programdata.set_owner(&system_program::id().to_bytes())?;
14781483
drop(programdata);
14791484

14801485
ic_logger_msg!(log_collector, "Migrated program {:?}", &program_address);
@@ -1813,7 +1818,7 @@ mod tests {
18131818
},
18141819
solana_pubkey::Pubkey,
18151820
solana_rent::Rent,
1816-
solana_sdk_ids::sysvar,
1821+
solana_sdk_ids::{system_program, sysvar},
18171822
solana_svm_feature_set::SVMFeatureSet,
18181823
std::{fs::File, io::Read, ops::Range, sync::atomic::AtomicU64},
18191824
};

programs/loader-v4/src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ fn process_instruction_set_program_length(
189189
let authority_address = instruction_context
190190
.get_index_of_instruction_account_in_transaction(1)
191191
.and_then(|index| transaction_context.get_key_of_account_at_index(index))?;
192-
let is_initialization =
193-
new_size > 0 && program.get_data().len() < LoaderV4State::program_data_offset();
192+
let is_initialization = program.get_data().len() < LoaderV4State::program_data_offset();
194193
if is_initialization {
195194
if !loader_v4::check_id(program.get_owner()) {
196195
ic_logger_msg!(log_collector, "Program not owned by loader");
@@ -1127,6 +1126,15 @@ mod tests {
11271126
),
11281127
);
11291128

1129+
// Close uninitialized program account
1130+
process_instruction(
1131+
vec![],
1132+
&bincode::serialize(&LoaderV4Instruction::SetProgramLength { new_size: 0 }).unwrap(),
1133+
transaction_accounts.clone(),
1134+
&[(3, false, true), (1, true, false), (2, true, true)],
1135+
Ok(()),
1136+
);
1137+
11301138
// Error: Program not owned by loader
11311139
process_instruction(
11321140
vec![],
@@ -1163,15 +1171,6 @@ mod tests {
11631171
Err(InstructionError::MissingRequiredSignature),
11641172
);
11651173

1166-
// Error: Program is and stays uninitialized
1167-
process_instruction(
1168-
vec![],
1169-
&bincode::serialize(&LoaderV4Instruction::SetProgramLength { new_size: 0 }).unwrap(),
1170-
transaction_accounts.clone(),
1171-
&[(3, false, true), (1, true, false), (2, true, true)],
1172-
Err(InstructionError::AccountDataTooSmall),
1173-
);
1174-
11751174
// Error: Program is not retracted
11761175
process_instruction(
11771176
vec![],

0 commit comments

Comments
 (0)