Skip to content

Commit

Permalink
Refactor: reorder C-style syscall CPI check order (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjain-jump authored Nov 14, 2024
1 parent 4c66d2f commit 938bd86
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
invoke_context.get_check_aligned(),
)?;

check_instruction_size(
ix_c.accounts_len as usize,
ix_c.data_len as usize,
invoke_context,
)?;
let program_id = translate_type::<Pubkey>(
memory_mapping,
ix_c.program_id_addr,
Expand All @@ -655,28 +650,28 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
ix_c.accounts_len,
invoke_context.get_check_aligned(),
)?;
let data = translate_slice::<u8>(
memory_mapping,
ix_c.data_addr,
ix_c.data_len,
invoke_context.get_check_aligned(),
)?
.to_vec();

check_instruction_size(ix_c.accounts_len as usize, data.len(), invoke_context)?;

let ix_data_len = ix_c.data_len;
if invoke_context
.get_feature_set()
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
consume_compute_meter(
invoke_context,
(ix_data_len)
(data.len() as u64)
.checked_div(invoke_context.get_compute_budget().cpi_bytes_per_unit)
.unwrap_or(u64::MAX),
)?;
}

let data = translate_slice::<u8>(
memory_mapping,
ix_c.data_addr,
ix_data_len,
invoke_context.get_check_aligned(),
)?
.to_vec();

let mut accounts = Vec::with_capacity(ix_c.accounts_len as usize);
#[allow(clippy::needless_range_loop)]
for account_index in 0..ix_c.accounts_len as usize {
Expand Down

0 comments on commit 938bd86

Please sign in to comment.