The syscall_saturated_math feature was activated, remove checks (#28605)

This commit is contained in:
Alessandro Decina 2022-11-23 20:42:59 +11:00 committed by GitHub
parent 638b26ea65
commit 1f40cb3d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 73 deletions

View File

@ -493,17 +493,7 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
InstructionError::InvalidArgument, InstructionError::InvalidArgument,
))? as *const _ as u64; ))? as *const _ as u64;
let addr = &account_info.data_len as *const u64 as u64; let addr = &account_info.data_len as *const u64 as u64;
let vm_addr = if invoke_context let vm_addr = account_infos_addr.saturating_add(addr.saturating_sub(first_info_addr));
.feature_set
.is_active(&syscall_saturated_math::id())
{
account_infos_addr.saturating_add(addr.saturating_sub(first_info_addr))
} else {
#[allow(clippy::integer_arithmetic)]
{
account_infos_addr + (addr - first_info_addr)
}
};
let _ = translate( let _ = translate(
memory_mapping, memory_mapping,
AccessType::Store, AccessType::Store,
@ -810,17 +800,8 @@ fn check_account_infos(
.into()); .into());
} }
} else { } else {
let adjusted_len = if invoke_context let adjusted_len = num_account_infos.saturating_mul(size_of::<Pubkey>());
.feature_set
.is_active(&syscall_saturated_math::id())
{
num_account_infos.saturating_mul(size_of::<Pubkey>())
} else {
#[allow(clippy::integer_arithmetic)]
{
num_account_infos * size_of::<Pubkey>()
}
};
if adjusted_len > invoke_context.get_compute_budget().max_cpi_instruction_size { if adjusted_len > invoke_context.get_compute_budget().max_cpi_instruction_size {
// Cap the number of account_infos a caller can pass to approximate // Cap the number of account_infos a caller can pass to approximate
// maximum that accounts that could be passed in an instruction // maximum that accounts that could be passed in an instruction
@ -927,20 +908,10 @@ fn cpi_common<S: SyscallInvokeSigned>(
*caller_account.owner = *callee_account.get_owner(); *caller_account.owner = *callee_account.get_owner();
let new_len = callee_account.get_data().len(); let new_len = callee_account.get_data().len();
if caller_account.data.len() != new_len { if caller_account.data.len() != new_len {
let data_overflow = if invoke_context let data_overflow = new_len
.feature_set > caller_account
.is_active(&syscall_saturated_math::id()) .original_data_len
{ .saturating_add(MAX_PERMITTED_DATA_INCREASE);
new_len
> caller_account
.original_data_len
.saturating_add(MAX_PERMITTED_DATA_INCREASE)
} else {
#[allow(clippy::integer_arithmetic)]
{
new_len > caller_account.original_data_len + MAX_PERMITTED_DATA_INCREASE
}
};
if data_overflow { if data_overflow {
ic_msg!( ic_msg!(
invoke_context, invoke_context,

View File

@ -134,17 +134,7 @@ declare_syscall!(
let a = *s1.get(i).ok_or(SyscallError::InvalidLength)?; let a = *s1.get(i).ok_or(SyscallError::InvalidLength)?;
let b = *s2.get(i).ok_or(SyscallError::InvalidLength)?; let b = *s2.get(i).ok_or(SyscallError::InvalidLength)?;
if a != b { if a != b {
*cmp_result = if invoke_context *cmp_result = (a as i32).saturating_sub(b as i32);
.feature_set
.is_active(&syscall_saturated_math::id())
{
(a as i32).saturating_sub(b as i32)
} else {
#[allow(clippy::integer_arithmetic)]
{
a as i32 - b as i32
}
};
return Ok(0); return Ok(0);
}; };
i = i.saturating_add(1); i = i.saturating_add(1);

View File

@ -37,7 +37,6 @@ use {
disable_cpi_setting_executable_and_rent_epoch, disable_fees_sysvar, disable_cpi_setting_executable_and_rent_epoch, disable_fees_sysvar,
enable_early_verification_of_account_modifications, libsecp256k1_0_5_upgrade_enabled, enable_early_verification_of_account_modifications, libsecp256k1_0_5_upgrade_enabled,
limit_secp256k1_recovery_id, stop_sibling_instruction_search_at_parent, limit_secp256k1_recovery_id, stop_sibling_instruction_search_at_parent,
syscall_saturated_math,
}, },
hash::{Hasher, HASH_BYTES}, hash::{Hasher, HASH_BYTES},
instruction::{ instruction::{
@ -1330,18 +1329,9 @@ declare_syscall!(
) -> Result<u64, EbpfError> { ) -> Result<u64, EbpfError> {
let budget = invoke_context.get_compute_budget(); let budget = invoke_context.get_compute_budget();
let cost = if invoke_context let cost = len
.feature_set .saturating_div(budget.cpi_bytes_per_unit)
.is_active(&syscall_saturated_math::id()) .saturating_add(budget.syscall_base_cost);
{
len.saturating_div(budget.cpi_bytes_per_unit)
.saturating_add(budget.syscall_base_cost)
} else {
#[allow(clippy::integer_arithmetic)]
{
len / budget.cpi_bytes_per_unit + budget.syscall_base_cost
}
};
consume_compute_meter(invoke_context, cost)?; consume_compute_meter(invoke_context, cost)?;
if len > MAX_RETURN_DATA as u64 { if len > MAX_RETURN_DATA as u64 {
@ -1395,19 +1385,9 @@ declare_syscall!(
let (program_id, return_data) = invoke_context.transaction_context.get_return_data(); let (program_id, return_data) = invoke_context.transaction_context.get_return_data();
length = length.min(return_data.len() as u64); length = length.min(return_data.len() as u64);
if length != 0 { if length != 0 {
let cost = if invoke_context let cost = length
.feature_set .saturating_add(size_of::<Pubkey>() as u64)
.is_active(&syscall_saturated_math::id()) .saturating_div(budget.cpi_bytes_per_unit);
{
length
.saturating_add(size_of::<Pubkey>() as u64)
.saturating_div(budget.cpi_bytes_per_unit)
} else {
#[allow(clippy::integer_arithmetic)]
{
(length + size_of::<Pubkey>() as u64) / budget.cpi_bytes_per_unit
}
};
consume_compute_meter(invoke_context, cost)?; consume_compute_meter(invoke_context, cost)?;
let return_data_result = translate_slice_mut::<u8>( let return_data_result = translate_slice_mut::<u8>(