Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit ff5e4ab

Browse files
committed
replaced dyn and box with second match
1 parent 516d35c commit ff5e4ab

File tree

1 file changed

+13
-10
lines changed
  • programs/bpf_loader/src/syscalls

1 file changed

+13
-10
lines changed

programs/bpf_loader/src/syscalls/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1676,20 +1676,17 @@ declare_syscall!(
16761676
memory_mapping: &mut MemoryMapping,
16771677
) -> Result<u64, EbpfError> {
16781678
use solana_sdk::alt_bn128::prelude::{ALT_BN128_ADD, ALT_BN128_MUL, ALT_BN128_PAIRING};
1679-
type DynAltBnFunction = Box<dyn for<'r> Fn(&'r [u8]) -> Result<Vec<u8>, AltBn128Error>>;
16801679

16811680
let budget = invoke_context.get_compute_budget();
16821681

1683-
let (cost, output, calculation): (u64, usize, DynAltBnFunction) = match group_op {
1682+
let (cost, output): (u64, usize) = match group_op {
16841683
ALT_BN128_ADD => (
16851684
budget.alt_bn128_addition_cost,
16861685
ALT_BN128_ADDITION_OUTPUT_LEN,
1687-
Box::new(alt_bn128_addition),
16881686
),
16891687
ALT_BN128_MUL => (
16901688
budget.alt_bn128_multiplication_cost,
16911689
ALT_BN128_MULTIPLICATION_OUTPUT_LEN,
1692-
Box::new(alt_bn128_multiplication),
16931690
),
16941691
ALT_BN128_PAIRING => {
16951692
let ele_len = input_size.saturating_div(ALT_BN128_PAIRING_ELEMENT_LEN as u64);
@@ -1703,16 +1700,13 @@ declare_syscall!(
17031700
.saturating_add(budget.sha256_base_cost)
17041701
.saturating_add(input_size)
17051702
.saturating_add(ALT_BN128_PAIRING_OUTPUT_LEN as u64);
1706-
(
1707-
cost,
1708-
ALT_BN128_PAIRING_OUTPUT_LEN,
1709-
Box::new(alt_bn128_pairing),
1710-
)
1703+
(cost, ALT_BN128_PAIRING_OUTPUT_LEN)
17111704
}
17121705
_ => {
17131706
return Err(SyscallError::InvalidAttribute.into());
17141707
}
17151708
};
1709+
17161710
invoke_context.get_compute_meter().consume(cost)?;
17171711

17181712
let input = translate_slice::<u8>(
@@ -1731,7 +1725,16 @@ declare_syscall!(
17311725
invoke_context.get_check_size(),
17321726
)?;
17331727

1734-
let result_point = match (*calculation)(input) {
1728+
let calculation = match group_op {
1729+
ALT_BN128_ADD => alt_bn128_addition,
1730+
ALT_BN128_MUL => alt_bn128_multiplication,
1731+
ALT_BN128_PAIRING => alt_bn128_pairing,
1732+
_ => {
1733+
return Err(SyscallError::InvalidAttribute.into());
1734+
}
1735+
};
1736+
1737+
let result_point = match calculation(input) {
17351738
Ok(result_point) => result_point,
17361739
Err(e) => {
17371740
return Ok(e.into());

0 commit comments

Comments
 (0)