Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Feature - Adds UpgradeableLoaderInstruction::Migrate (#4661)" #4870

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-keccak-hasher = { workspace = true }
solana-loader-v3-interface = { workspace = true, features = ["serde"] }
solana-loader-v4-interface = { workspace = true, features = ["bincode"] }
solana-loader-v4-interface = { workspace = true, optional = true }
solana-log-collector = { workspace = true }
solana-measure = { workspace = true }
solana-packet = { workspace = true }
Expand Down Expand Up @@ -92,4 +92,4 @@ shuttle-test = [
"solana-program-runtime/shuttle-test",
"solana-sbpf/shuttle-test"
]
svm-internal = []
svm-internal = ["dep:solana-loader-v4-interface"]
184 changes: 3 additions & 181 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use {
solana_compute_budget::compute_budget::MAX_INSTRUCTION_STACK_DEPTH,
solana_feature_set::{
bpf_account_data_direct_mapping, disable_new_loader_v3_deployments,
enable_bpf_loader_set_authority_checked_ix, enable_loader_v4,
remove_accounts_executable_flag_checks,
enable_bpf_loader_set_authority_checked_ix, remove_accounts_executable_flag_checks,
},
solana_instruction::{error::InstructionError, AccountMeta},
solana_loader_v3_interface::{
Expand Down Expand Up @@ -44,10 +43,7 @@ use {
verifier::RequisiteVerifier,
vm::{ContextObject, EbpfVm},
},
solana_sdk_ids::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4, native_loader,
system_program,
},
solana_sdk_ids::{bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, native_loader},
solana_system_interface::{instruction as system_instruction, MAX_PERMITTED_DATA_LENGTH},
solana_transaction_context::{IndexOfAccount, InstructionContext, TransactionContext},
solana_type_overrides::sync::{atomic::Ordering, Arc},
Expand Down Expand Up @@ -397,10 +393,6 @@ declare_builtin_function!(
}
);

mod migration_authority {
solana_pubkey::declare_id!("3Scf35jMNk2xXBD6areNjgMtXgp5ZspDhms8vdcbzC42");
}

#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
pub(crate) fn process_instruction_inner(
invoke_context: &mut InvokeContext,
Expand Down Expand Up @@ -1344,176 +1336,6 @@ fn process_loader_upgradeable_instruction(
additional_bytes
);
}
UpgradeableLoaderInstruction::Migrate => {
if !invoke_context
.get_feature_set()
.is_active(&enable_loader_v4::id())
{
return Err(InstructionError::InvalidInstructionData);
}

instruction_context.check_number_of_instruction_accounts(3)?;
let programdata_address = *transaction_context.get_key_of_account_at_index(
instruction_context.get_index_of_instruction_account_in_transaction(0)?,
)?;
let program_address = *transaction_context.get_key_of_account_at_index(
instruction_context.get_index_of_instruction_account_in_transaction(1)?,
)?;
let provided_authority_address = *transaction_context.get_key_of_account_at_index(
instruction_context.get_index_of_instruction_account_in_transaction(2)?,
)?;
let clock_slot = invoke_context
.get_sysvar_cache()
.get_clock()
.map(|clock| clock.slot)?;

// Verify ProgramData account
let programdata =
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
if !programdata.is_writable() {
ic_logger_msg!(log_collector, "ProgramData account not writeable");
return Err(InstructionError::InvalidArgument);
}
let (program_len, upgrade_authority_address) =
if let Ok(UpgradeableLoaderState::ProgramData {
slot,
upgrade_authority_address,
}) = programdata.get_state()
{
if clock_slot == slot {
ic_logger_msg!(log_collector, "Program was deployed in this block already");
return Err(InstructionError::InvalidArgument);
}
(
programdata
.get_data()
.len()
.saturating_sub(UpgradeableLoaderState::size_of_programdata_metadata()),
upgrade_authority_address,
)
} else {
(0, None)
};
let programdata_funds = programdata.get_lamports();
drop(programdata);

// Verify authority signature
if !migration_authority::check_id(&provided_authority_address)
&& provided_authority_address
!= upgrade_authority_address.unwrap_or(program_address)
{
ic_logger_msg!(log_collector, "Incorrect migration authority provided");
return Err(InstructionError::IncorrectAuthority);
}
if !instruction_context.is_instruction_account_signer(2)? {
ic_logger_msg!(log_collector, "Migration authority did not sign");
return Err(InstructionError::MissingRequiredSignature);
}

// Verify Program account
let mut program =
instruction_context.try_borrow_instruction_account(transaction_context, 1)?;
if !program.is_writable() {
ic_logger_msg!(log_collector, "Program account not writeable");
return Err(InstructionError::InvalidArgument);
}
if program.get_owner() != program_id {
ic_logger_msg!(log_collector, "Program account not owned by loader");
return Err(InstructionError::IncorrectProgramId);
}
if let UpgradeableLoaderState::Program {
programdata_address: stored_programdata_address,
} = program.get_state()?
{
if programdata_address != stored_programdata_address {
ic_logger_msg!(log_collector, "Program and ProgramData account mismatch");
return Err(InstructionError::InvalidArgument);
}
} else {
ic_logger_msg!(log_collector, "Invalid Program account");
return Err(InstructionError::InvalidAccountData);
}
program.set_data_from_slice(&[])?;
program.checked_add_lamports(programdata_funds)?;
if program_len == 0 {
program.set_owner(&system_program::id().to_bytes())?;
} else {
program.set_owner(&loader_v4::id().to_bytes())?;
}
drop(program);

let mut programdata =
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
programdata.set_lamports(0)?;
drop(programdata);

if program_len > 0 {
invoke_context.native_invoke(
solana_loader_v4_interface::instruction::set_program_length(
&program_address,
&provided_authority_address,
program_len as u32,
&program_address,
)
.into(),
&[],
)?;

invoke_context.native_invoke(
solana_loader_v4_interface::instruction::copy(
&program_address,
&provided_authority_address,
&programdata_address,
0,
0,
program_len as u32,
)
.into(),
&[],
)?;

invoke_context.native_invoke(
solana_loader_v4_interface::instruction::deploy(
&program_address,
&provided_authority_address,
)
.into(),
&[],
)?;

if upgrade_authority_address.is_none() {
invoke_context.native_invoke(
solana_loader_v4_interface::instruction::finalize(
&program_address,
&provided_authority_address,
&program_address,
)
.into(),
&[],
)?;
} else if migration_authority::check_id(&provided_authority_address) {
invoke_context.native_invoke(
solana_loader_v4_interface::instruction::transfer_authority(
&program_address,
&provided_authority_address,
&upgrade_authority_address.unwrap(),
)
.into(),
&[],
)?;
}
}

let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let mut programdata =
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
programdata.set_data_from_slice(&[])?;
programdata.set_owner(&system_program::id().to_bytes())?;
drop(programdata);

ic_logger_msg!(log_collector, "Migrated program {:?}", &program_address);
}
}

Ok(())
Expand Down Expand Up @@ -1847,7 +1669,7 @@ mod tests {
},
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_sdk_ids::sysvar,
solana_sdk_ids::{system_program, sysvar},
std::{fs::File, io::Read, ops::Range, sync::atomic::AtomicU64},
};

Expand Down
Loading
Loading