Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jul 20, 2022
1 parent 1482da6 commit 861df8e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ thiserror = "1.0"
[dev-dependencies]
rand = "0.7.3"
solana-runtime = { path = "../../runtime", version = "=1.11.4" }
static_assertions = "1.1.0"

[lib]
crate-type = ["lib"]
Expand Down
42 changes: 29 additions & 13 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,22 @@ impl<'a, 'b> SyscallInvokeSigned<'a, 'b> for SyscallInvokeSignedRust<'a, 'b> {
invoke_context.get_check_size(),
)?
.to_vec();

let ix_data_len = ix.data.len() as u64;
if invoke_context
.feature_set
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
invoke_context.get_compute_meter().consume(
(ix_data_len)
.saturating_div(invoke_context.get_compute_budget().cpi_bytes_per_unit),
)?;
}

let data = translate_slice::<u8>(
memory_mapping,
ix.data.as_ptr() as u64,
ix.data.len() as u64,
ix_data_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
Expand Down Expand Up @@ -399,10 +411,22 @@ impl<'a, 'b> SyscallInvokeSigned<'a, 'b> for SyscallInvokeSignedC<'a, 'b> {
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;

let ix_data_len = ix_c.data_len as u64;
if invoke_context
.feature_set
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
invoke_context.get_compute_meter().consume(
(ix_data_len)
.saturating_div(invoke_context.get_compute_budget().cpi_bytes_per_unit),
)?;
}

let data = translate_slice::<u8>(
memory_mapping,
ix_c.data_addr,
ix_c.data_len as u64,
ix_data_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
Expand Down Expand Up @@ -739,18 +763,14 @@ where
Ok(accounts)
}

#[cfg(test)]
static_assertions::const_assert_eq!(ACCOUNT_META_SIZE, 34);
const ACCOUNT_META_SIZE: usize = size_of::<AccountMeta>();

fn check_instruction_size(
num_accounts: usize,
data_len: usize,
invoke_context: &mut InvokeContext,
) -> Result<(), EbpfError<BpfError>> {
if invoke_context
.feature_set
.is_active(&feature_set::loosen_cpi_size_restriction::ID)
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
let data_len = data_len as u64;
let max_data_len = MAX_CPI_INSTRUCTION_DATA_LEN;
Expand All @@ -771,14 +791,10 @@ fn check_instruction_size(
}
.into());
}

invoke_context.get_compute_meter().consume(
(data_len).saturating_div(invoke_context.get_compute_budget().cpi_bytes_per_unit),
)?;
} else {
let max_size = invoke_context.get_compute_budget().max_cpi_instruction_size;
let size = num_accounts
.saturating_mul(ACCOUNT_META_SIZE)
.saturating_mul(size_of::<AccountMeta>())
.saturating_add(data_len);
if size > max_size {
return Err(SyscallError::InstructionTooLarge(size, max_size).into());
Expand All @@ -793,7 +809,7 @@ fn check_account_infos(
) -> Result<(), EbpfError<BpfError>> {
if invoke_context
.feature_set
.is_active(&feature_set::loosen_cpi_size_restriction::ID)
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
let num_account_infos = num_account_infos as u64;
let max_account_infos = MAX_CPI_ACCOUNT_INFOS as u64;
Expand Down

0 comments on commit 861df8e

Please sign in to comment.