From 15d46c2cdec6e0b7bfcbcce5de3b477bb7e696e3 Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Wed, 15 May 2024 14:21:37 -0700 Subject: [PATCH] use floored checked div --- programs/bpf_loader/src/syscalls/sysvar.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/programs/bpf_loader/src/syscalls/sysvar.rs b/programs/bpf_loader/src/syscalls/sysvar.rs index 8d8fa667830e4d..a61b304feb208a 100644 --- a/programs/bpf_loader/src/syscalls/sysvar.rs +++ b/programs/bpf_loader/src/syscalls/sysvar.rs @@ -187,14 +187,13 @@ declare_builtin_function!( } = *invoke_context.get_compute_budget(); // Abort: "Compute budget is exceeded." + let sysvar_id_cost = 32_u64.checked_div(cpi_bytes_per_unit).unwrap_or(0); + let sysvar_buf_cost = length.checked_div(cpi_bytes_per_unit).unwrap_or(0); consume_compute_meter( invoke_context, sysvar_base_cost - .saturating_add(32_u64.div_ceil(cpi_bytes_per_unit)) - .saturating_add(std::cmp::max( - length.div_ceil(cpi_bytes_per_unit), - mem_op_base_cost, - )), + .saturating_add(sysvar_id_cost) + .saturating_add(std::cmp::max(sysvar_buf_cost, mem_op_base_cost)), )?; // Abort: "Not all bytes in VM memory range `[sysvar_id, sysvar_id + 32)` are readable."