Skip to content

Commit 2eb1b92

Browse files
committed
Adjust gas values, move out variables
1 parent 1bcf5b0 commit 2eb1b92

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

packages/vm/src/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Default for GasConfig {
8585
bls12_381_hash_to_g1_cost: 324 * GAS_PER_US,
8686
bls12_381_hash_to_g2_cost: 528 * GAS_PER_US,
8787
// god i wish i was lying
88-
bls12_381_pairing_equality_cost: 1254 * GAS_PER_US,
88+
bls12_381_pairing_equality_cost: 1038 * GAS_PER_US,
8989
bls12_381_aggregated_pairing_equality_cost_per_pair: 108 * GAS_PER_US,
9090
}
9191
}

packages/vm/src/imports.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ pub fn do_bls12_381_aggregate_g1<
276276

277277
let g1s = read_region(&memory, g1s_ptr, BLS12_381_MAX_AGGREGATE_SIZE)?;
278278

279+
let estimated_point_count = (g1s.len() / BLS12_381_G1_POINT_LEN) as u64;
279280
let gas_info = GasInfo::with_cost(
280-
data.gas_config.bls12_381_aggregate_g1_per_point
281-
* (g1s.len() / BLS12_381_G1_POINT_LEN) as u64,
281+
data.gas_config.bls12_381_aggregate_g1_per_point * estimated_point_count,
282282
);
283283
process_gas_info(data, &mut store, gas_info)?;
284284

@@ -320,9 +320,9 @@ pub fn do_bls12_381_aggregate_g2<
320320

321321
let g2s = read_region(&memory, g2s_ptr, BLS12_381_MAX_AGGREGATE_SIZE)?;
322322

323+
let estimated_point_count = (g2s.len() / BLS12_381_G2_POINT_LEN) as u64;
323324
let gas_info = GasInfo::with_cost(
324-
data.gas_config.bls12_381_aggregate_g2_per_point
325-
* (g2s.len() / BLS12_381_G2_POINT_LEN) as u64,
325+
data.gas_config.bls12_381_aggregate_g2_per_point * estimated_point_count,
326326
);
327327
process_gas_info(data, &mut store, gas_info)?;
328328

@@ -369,14 +369,15 @@ pub fn do_bls12_381_pairing_equality<
369369
let r = read_region(&memory, r_ptr, BLS12_381_G1_POINT_LEN)?;
370370
let s = read_region(&memory, s_ptr, BLS12_381_G2_POINT_LEN)?;
371371

372-
let gas_info = GasInfo::with_cost(
373-
data.gas_config.bls12_381_pairing_equality_cost
374-
// Subtract one since the base benchmark of the pairing equality cost includes a single pair already
375-
+ (data
376-
.gas_config
377-
.bls12_381_aggregated_pairing_equality_cost_per_pair
378-
* (ps.len() / BLS12_381_G1_POINT_LEN) as u64).saturating_sub(1),
379-
);
372+
let estimated_point_count = (ps.len() / BLS12_381_G1_POINT_LEN) as u64;
373+
let additional_cost = data
374+
.gas_config
375+
.bls12_381_aggregated_pairing_equality_cost_per_pair
376+
// 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.
377+
* (estimated_point_count + 1);
378+
379+
let gas_info =
380+
GasInfo::with_cost(data.gas_config.bls12_381_pairing_equality_cost + additional_cost);
380381
process_gas_info(data, &mut store, gas_info)?;
381382

382383
let code = match bls12_381_pairing_equality(&ps, &qs, &r, &s) {

0 commit comments

Comments
 (0)