From 2eb1b923bfd86faf1c6c1246cd8328ffe025de65 Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Fri, 10 May 2024 14:56:00 +0200 Subject: [PATCH] Adjust gas values, move out variables --- packages/vm/src/environment.rs | 2 +- packages/vm/src/imports.rs | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/vm/src/environment.rs b/packages/vm/src/environment.rs index 98641dac70..e30a0877e2 100644 --- a/packages/vm/src/environment.rs +++ b/packages/vm/src/environment.rs @@ -85,7 +85,7 @@ impl Default for GasConfig { bls12_381_hash_to_g1_cost: 324 * GAS_PER_US, bls12_381_hash_to_g2_cost: 528 * GAS_PER_US, // god i wish i was lying - bls12_381_pairing_equality_cost: 1254 * GAS_PER_US, + bls12_381_pairing_equality_cost: 1038 * GAS_PER_US, bls12_381_aggregated_pairing_equality_cost_per_pair: 108 * GAS_PER_US, } } diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index 33469d9cb0..ef86c276db 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -276,9 +276,9 @@ pub fn do_bls12_381_aggregate_g1< let g1s = read_region(&memory, g1s_ptr, BLS12_381_MAX_AGGREGATE_SIZE)?; + let estimated_point_count = (g1s.len() / BLS12_381_G1_POINT_LEN) as u64; let gas_info = GasInfo::with_cost( - data.gas_config.bls12_381_aggregate_g1_per_point - * (g1s.len() / BLS12_381_G1_POINT_LEN) as u64, + data.gas_config.bls12_381_aggregate_g1_per_point * estimated_point_count, ); process_gas_info(data, &mut store, gas_info)?; @@ -320,9 +320,9 @@ pub fn do_bls12_381_aggregate_g2< let g2s = read_region(&memory, g2s_ptr, BLS12_381_MAX_AGGREGATE_SIZE)?; + let estimated_point_count = (g2s.len() / BLS12_381_G2_POINT_LEN) as u64; let gas_info = GasInfo::with_cost( - data.gas_config.bls12_381_aggregate_g2_per_point - * (g2s.len() / BLS12_381_G2_POINT_LEN) as u64, + data.gas_config.bls12_381_aggregate_g2_per_point * estimated_point_count, ); process_gas_info(data, &mut store, gas_info)?; @@ -369,14 +369,15 @@ pub fn do_bls12_381_pairing_equality< let r = read_region(&memory, r_ptr, BLS12_381_G1_POINT_LEN)?; let s = read_region(&memory, s_ptr, BLS12_381_G2_POINT_LEN)?; - let gas_info = GasInfo::with_cost( - data.gas_config.bls12_381_pairing_equality_cost - // Subtract one since the base benchmark of the pairing equality cost includes a single pair already - + (data - .gas_config - .bls12_381_aggregated_pairing_equality_cost_per_pair - * (ps.len() / BLS12_381_G1_POINT_LEN) as u64).saturating_sub(1), - ); + let estimated_point_count = (ps.len() / BLS12_381_G1_POINT_LEN) as u64; + let additional_cost = data + .gas_config + .bls12_381_aggregated_pairing_equality_cost_per_pair + // Add one since we do not include any pairs in the base benchmark, and we always need to add one for the `r` and `s` pair. + * (estimated_point_count + 1); + + let gas_info = + GasInfo::with_cost(data.gas_config.bls12_381_pairing_equality_cost + additional_cost); process_gas_info(data, &mut store, gas_info)?; let code = match bls12_381_pairing_equality(&ps, &qs, &r, &s) {