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,
))? as *const _ as u64;
let addr = &account_info.data_len as *const u64 as u64;
let vm_addr = if invoke_context
.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 vm_addr = account_infos_addr.saturating_add(addr.saturating_sub(first_info_addr));
let _ = translate(
memory_mapping,
AccessType::Store,
@ -810,17 +800,8 @@ fn check_account_infos(
.into());
}
} else {
let adjusted_len = if invoke_context
.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>()
}
};
let adjusted_len = num_account_infos.saturating_mul(size_of::<Pubkey>());
if adjusted_len > invoke_context.get_compute_budget().max_cpi_instruction_size {
// Cap the number of account_infos a caller can pass to approximate
// 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();
let new_len = callee_account.get_data().len();
if caller_account.data.len() != new_len {
let data_overflow = if invoke_context
.feature_set
.is_active(&syscall_saturated_math::id())
{
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
}
};
let data_overflow = new_len
> caller_account
.original_data_len
.saturating_add(MAX_PERMITTED_DATA_INCREASE);
if data_overflow {
ic_msg!(
invoke_context,

View File

@ -134,17 +134,7 @@ declare_syscall!(
let a = *s1.get(i).ok_or(SyscallError::InvalidLength)?;
let b = *s2.get(i).ok_or(SyscallError::InvalidLength)?;
if a != b {
*cmp_result = if invoke_context
.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
}
};
*cmp_result = (a as i32).saturating_sub(b as i32);
return Ok(0);
};
i = i.saturating_add(1);

View File

@ -37,7 +37,6 @@ use {
disable_cpi_setting_executable_and_rent_epoch, disable_fees_sysvar,
enable_early_verification_of_account_modifications, libsecp256k1_0_5_upgrade_enabled,
limit_secp256k1_recovery_id, stop_sibling_instruction_search_at_parent,
syscall_saturated_math,
},
hash::{Hasher, HASH_BYTES},
instruction::{
@ -1330,18 +1329,9 @@ declare_syscall!(
) -> Result<u64, EbpfError> {
let budget = invoke_context.get_compute_budget();
let cost = if invoke_context
.feature_set
.is_active(&syscall_saturated_math::id())
{
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
}
};
let cost = len
.saturating_div(budget.cpi_bytes_per_unit)
.saturating_add(budget.syscall_base_cost);
consume_compute_meter(invoke_context, cost)?;
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();
length = length.min(return_data.len() as u64);
if length != 0 {
let cost = if invoke_context
.feature_set
.is_active(&syscall_saturated_math::id())
{
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
}
};
let cost = length
.saturating_add(size_of::<Pubkey>() as u64)
.saturating_div(budget.cpi_bytes_per_unit);
consume_compute_meter(invoke_context, cost)?;
let return_data_result = translate_slice_mut::<u8>(