Cleanup loader features (#18977)

This commit is contained in:
Jack May
2021-07-29 15:03:00 -07:00
committed by GitHub
parent b05fb87f22
commit ef17cf3bdb
3 changed files with 42 additions and 96 deletions

View File

@ -31,7 +31,7 @@ use solana_sdk::{
bpf_loader_upgradeable::{self, UpgradeableLoaderState}, bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Clock, clock::Clock,
entrypoint::{HEAP_LENGTH, SUCCESS}, entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{add_missing_program_error_mappings, upgradeable_close_instruction}, feature_set::add_missing_program_error_mappings,
ic_logger_msg, ic_msg, ic_logger_msg, ic_msg,
instruction::InstructionError, instruction::InstructionError,
keyed_account::{from_keyed_account, keyed_account_at_index}, keyed_account::{from_keyed_account, keyed_account_at_index},
@ -620,9 +620,6 @@ fn process_loader_upgradeable_instruction(
ic_logger_msg!(logger, "New authority {:?}", new_authority); ic_logger_msg!(logger, "New authority {:?}", new_authority);
} }
UpgradeableLoaderInstruction::Close => { UpgradeableLoaderInstruction::Close => {
if !invoke_context.is_feature_active(&upgradeable_close_instruction::id()) {
return Err(InstructionError::InvalidInstructionData);
}
let close_account = keyed_account_at_index(keyed_accounts, 0)?; let close_account = keyed_account_at_index(keyed_accounts, 0)?;
let recipient_account = keyed_account_at_index(keyed_accounts, 1)?; let recipient_account = keyed_account_at_index(keyed_accounts, 1)?;
let authority = keyed_account_at_index(keyed_accounts, 2)?; let authority = keyed_account_at_index(keyed_accounts, 2)?;

View File

@ -21,9 +21,8 @@ use solana_sdk::{
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS}, entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
epoch_schedule::EpochSchedule, epoch_schedule::EpochSchedule,
feature_set::{ feature_set::{
blake3_syscall_enabled, cpi_data_cost, enforce_aligned_host_addrs, blake3_syscall_enabled, enforce_aligned_host_addrs, libsecp256k1_0_5_upgrade_enabled,
keccak256_syscall_enabled, libsecp256k1_0_5_upgrade_enabled, memory_ops_syscalls, memory_ops_syscalls, secp256k1_recover_syscall_enabled,
secp256k1_recover_syscall_enabled, sysvar_via_syscall, update_data_on_realloc,
}, },
hash::{Hasher, HASH_BYTES}, hash::{Hasher, HASH_BYTES},
ic_msg, ic_msg,
@ -134,10 +133,7 @@ pub fn register_syscalls(
)?; )?;
syscall_registry.register_syscall_by_name(b"sol_sha256", SyscallSha256::call)?; syscall_registry.register_syscall_by_name(b"sol_sha256", SyscallSha256::call)?;
syscall_registry.register_syscall_by_name(b"sol_keccak256", SyscallKeccak256::call)?;
if invoke_context.is_feature_active(&keccak256_syscall_enabled::id()) {
syscall_registry.register_syscall_by_name(b"sol_keccak256", SyscallKeccak256::call)?;
}
if invoke_context.is_feature_active(&secp256k1_recover_syscall_enabled::id()) { if invoke_context.is_feature_active(&secp256k1_recover_syscall_enabled::id()) {
syscall_registry syscall_registry
@ -148,18 +144,16 @@ pub fn register_syscalls(
syscall_registry.register_syscall_by_name(b"sol_blake3", SyscallBlake3::call)?; syscall_registry.register_syscall_by_name(b"sol_blake3", SyscallBlake3::call)?;
} }
if invoke_context.is_feature_active(&sysvar_via_syscall::id()) { syscall_registry
syscall_registry .register_syscall_by_name(b"sol_get_clock_sysvar", SyscallGetClockSysvar::call)?;
.register_syscall_by_name(b"sol_get_clock_sysvar", SyscallGetClockSysvar::call)?; syscall_registry.register_syscall_by_name(
syscall_registry.register_syscall_by_name( b"sol_get_epoch_schedule_sysvar",
b"sol_get_epoch_schedule_sysvar", SyscallGetEpochScheduleSysvar::call,
SyscallGetEpochScheduleSysvar::call, )?;
)?; syscall_registry
syscall_registry .register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?;
.register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?; syscall_registry
syscall_registry .register_syscall_by_name(b"sol_get_rent_sysvar", SyscallGetRentSysvar::call)?;
.register_syscall_by_name(b"sol_get_rent_sysvar", SyscallGetRentSysvar::call)?;
}
if invoke_context.is_feature_active(&memory_ops_syscalls::id()) { if invoke_context.is_feature_active(&memory_ops_syscalls::id()) {
syscall_registry.register_syscall_by_name(b"sol_memcpy_", SyscallMemcpy::call)?; syscall_registry.register_syscall_by_name(b"sol_memcpy_", SyscallMemcpy::call)?;
@ -283,16 +277,15 @@ pub fn bind_syscall_context_objects<'a>(
None, None,
)?; )?;
bind_feature_gated_syscall_context_object!( vm.bind_syscall_context_object(
vm,
invoke_context.is_feature_active(&keccak256_syscall_enabled::id()),
Box::new(SyscallKeccak256 { Box::new(SyscallKeccak256 {
base_cost: compute_budget.sha256_base_cost, base_cost: compute_budget.sha256_base_cost,
byte_cost: compute_budget.sha256_byte_cost, byte_cost: compute_budget.sha256_byte_cost,
compute_meter: invoke_context.get_compute_meter(), compute_meter: invoke_context.get_compute_meter(),
loader_id, loader_id,
}), }),
); None,
)?;
bind_feature_gated_syscall_context_object!( bind_feature_gated_syscall_context_object!(
vm, vm,
@ -353,42 +346,36 @@ pub fn bind_syscall_context_objects<'a>(
}), }),
); );
let is_sysvar_via_syscall_active = invoke_context.is_feature_active(&sysvar_via_syscall::id());
let invoke_context = Rc::new(RefCell::new(invoke_context)); let invoke_context = Rc::new(RefCell::new(invoke_context));
bind_feature_gated_syscall_context_object!( vm.bind_syscall_context_object(
vm,
is_sysvar_via_syscall_active,
Box::new(SyscallGetClockSysvar { Box::new(SyscallGetClockSysvar {
invoke_context: invoke_context.clone(), invoke_context: invoke_context.clone(),
loader_id, loader_id,
}), }),
); None,
bind_feature_gated_syscall_context_object!( )?;
vm, vm.bind_syscall_context_object(
is_sysvar_via_syscall_active,
Box::new(SyscallGetEpochScheduleSysvar { Box::new(SyscallGetEpochScheduleSysvar {
invoke_context: invoke_context.clone(), invoke_context: invoke_context.clone(),
loader_id, loader_id,
}), }),
); None,
bind_feature_gated_syscall_context_object!( )?;
vm, vm.bind_syscall_context_object(
is_sysvar_via_syscall_active,
Box::new(SyscallGetFeesSysvar { Box::new(SyscallGetFeesSysvar {
invoke_context: invoke_context.clone(), invoke_context: invoke_context.clone(),
loader_id, loader_id,
}), }),
); None,
bind_feature_gated_syscall_context_object!( )?;
vm, vm.bind_syscall_context_object(
is_sysvar_via_syscall_active,
Box::new(SyscallGetRentSysvar { Box::new(SyscallGetRentSysvar {
invoke_context: invoke_context.clone(), invoke_context: invoke_context.clone(),
loader_id, loader_id,
}), }),
); None,
)?;
// Cross-program invocation syscalls // Cross-program invocation syscalls
vm.bind_syscall_context_object( vm.bind_syscall_context_object(
@ -1690,11 +1677,9 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedRust<'a> {
enforce_aligned_host_addrs, enforce_aligned_host_addrs,
)?; )?;
if invoke_context.is_feature_active(&cpi_data_cost::id()) { invoke_context.get_compute_meter().consume(
invoke_context.get_compute_meter().consume( data.len() as u64 / invoke_context.get_compute_budget().cpi_bytes_per_unit,
data.len() as u64 / invoke_context.get_compute_budget().cpi_bytes_per_unit, )?;
)?;
}
let translated = translate( let translated = translate(
memory_mapping, memory_mapping,
@ -2009,11 +1994,9 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedC<'a> {
)?; )?;
let vm_data_addr = account_info.data_addr; let vm_data_addr = account_info.data_addr;
if invoke_context.is_feature_active(&cpi_data_cost::id()) { invoke_context.get_compute_meter().consume(
invoke_context.get_compute_meter().consume( account_info.data_len / invoke_context.get_compute_budget().cpi_bytes_per_unit,
account_info.data_len / invoke_context.get_compute_budget().cpi_bytes_per_unit, )?;
)?;
}
let data = translate_slice_mut::<u8>( let data = translate_slice_mut::<u8>(
memory_mapping, memory_mapping,
@ -2440,22 +2423,13 @@ fn call<'a>(
) )
.into()); .into());
} }
if invoke_context.is_feature_active(&update_data_on_realloc::id()) { account_ref.data = translate_slice_mut::<u8>(
account_ref.data = translate_slice_mut::<u8>( memory_mapping,
memory_mapping, account_ref.vm_data_addr,
account_ref.vm_data_addr, account.data().len() as u64,
account.data().len() as u64, &bpf_loader_deprecated::id(), // Don't care since it is byte aligned
&bpf_loader_deprecated::id(), // Don't care since it is byte aligned true,
true, )?;
)?;
} else {
let _ = translate(
memory_mapping,
AccessType::Store,
account_ref.vm_data_addr,
account.data().len() as u64,
)?;
}
*account_ref.ref_to_len_in_vm = account.data().len() as u64; *account_ref.ref_to_len_in_vm = account.data().len() as u64;
*account_ref.serialized_len_ptr = account.data().len() as u64; *account_ref.serialized_len_ptr = account.data().len() as u64;
} }

View File

@ -107,30 +107,10 @@ pub mod require_stake_for_gossip {
solana_sdk::declare_id!("6oNzd5Z3M2L1xo4Q5hoox7CR2DuW7m1ETLWH5jHJthwa"); solana_sdk::declare_id!("6oNzd5Z3M2L1xo4Q5hoox7CR2DuW7m1ETLWH5jHJthwa");
} }
pub mod cpi_data_cost {
solana_sdk::declare_id!("Hrg5bXePPGiAVWZfDHbvjqytSeyBDPAGAQ7v6N5i4gCX");
}
pub mod upgradeable_close_instruction {
solana_sdk::declare_id!("FsPaByos3gA9bUEhp3EimQpQPCoSvCEigHod496NmABQ");
}
pub mod sysvar_via_syscall {
solana_sdk::declare_id!("7411E6gFQLDhQkdRjmpXwM1hzHMMoYQUjHicmvGPC1Nf");
}
pub mod enforce_aligned_host_addrs { pub mod enforce_aligned_host_addrs {
solana_sdk::declare_id!("6Qob9Z4RwGdf599FDVCqsjuKjR8ZFR3oVs2ByRLWBsua"); solana_sdk::declare_id!("6Qob9Z4RwGdf599FDVCqsjuKjR8ZFR3oVs2ByRLWBsua");
} }
pub mod update_data_on_realloc {
solana_sdk::declare_id!("BkPcYCrwHXBoTsv9vMhiRF9gteZmDj3Uwisz9CDjoMKp");
}
pub mod keccak256_syscall_enabled {
solana_sdk::declare_id!("7Ua8mFtahVfA3WCY9LoXDAJJdvJRJHckvSSr1dD8FTWc");
}
pub mod stake_program_v4 { pub mod stake_program_v4 {
solana_sdk::declare_id!("Dc7djyhP9aLfdq2zktpvskeAjpG56msCU1yexpxXiWZb"); solana_sdk::declare_id!("Dc7djyhP9aLfdq2zktpvskeAjpG56msCU1yexpxXiWZb");
} }
@ -217,12 +197,7 @@ lazy_static! {
(check_init_vote_data::id(), "check initialized Vote data"), (check_init_vote_data::id(), "check initialized Vote data"),
(check_program_owner::id(), "limit programs to operating on accounts owned by itself"), (check_program_owner::id(), "limit programs to operating on accounts owned by itself"),
(require_stake_for_gossip::id(), "require stakes for propagating crds values through gossip #15561"), (require_stake_for_gossip::id(), "require stakes for propagating crds values through gossip #15561"),
(cpi_data_cost::id(), "charge the compute budget for data passed via CPI"),
(upgradeable_close_instruction::id(), "close upgradeable buffer accounts"),
(sysvar_via_syscall::id(), "provide sysvars via syscalls"),
(enforce_aligned_host_addrs::id(), "enforce aligned host addresses"), (enforce_aligned_host_addrs::id(), "enforce aligned host addresses"),
(update_data_on_realloc::id(), "Retain updated data values modified after realloc via CPI"),
(keccak256_syscall_enabled::id(), "keccak256 syscall"),
(stake_program_v4::id(), "solana_stake_program v4"), (stake_program_v4::id(), "solana_stake_program v4"),
(memory_ops_syscalls::id(), "add syscalls for memory operations"), (memory_ops_syscalls::id(), "add syscalls for memory operations"),
(secp256k1_recover_syscall_enabled::id(), "secp256k1_recover syscall"), (secp256k1_recover_syscall_enabled::id(), "secp256k1_recover syscall"),