From 0fa45041cc722e6728ea318e4b7569021e0e0b81 Mon Sep 17 00:00:00 2001 From: xkx Date: Tue, 29 Aug 2023 21:13:54 +0800 Subject: [PATCH] fix: pairing cost formula (#659) * fix pairing cost formula bug * chore: fmt --------- Co-authored-by: Rohit Narurkar --- crates/precompile/src/bn128.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 70be85bf00..8d82a01db7 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -165,8 +165,7 @@ fn run_pair( pair_base_cost: u64, gas_limit: u64, ) -> PrecompileResult { - let gas_used = - pair_per_point_cost * input.len() as u64 / PAIR_ELEMENT_LEN as u64 + pair_base_cost; + let gas_used = (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; if gas_used > gas_limit { return Err(Error::OutOfGas); }