From 32ad4f01a4e8d6db7c93825db1818ced43d5a21b Mon Sep 17 00:00:00 2001 From: kunxian xia Date: Tue, 29 Aug 2023 16:58:58 +0800 Subject: [PATCH 1/2] fix pairing cost formula bug --- crates/precompile/src/bn128.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 70be85bf00..9c3640ae66 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -166,7 +166,7 @@ fn run_pair( gas_limit: u64, ) -> PrecompileResult { let gas_used = - pair_per_point_cost * input.len() as u64 / PAIR_ELEMENT_LEN as u64 + pair_base_cost; + (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; if gas_used > gas_limit { return Err(Error::OutOfGas); } From 928337d9c6f6b4b61baf9ab35fc740d17ae77949 Mon Sep 17 00:00:00 2001 From: Rohit Narurkar Date: Tue, 29 Aug 2023 11:31:26 +0100 Subject: [PATCH 2/2] chore: fmt --- 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 9c3640ae66..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 = - (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + 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); }