Skip to content

Commit 86fe644

Browse files
committed
Update bls12_318 gas cost
1 parent 58b2353 commit 86fe644

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

packages/vm/src/environment.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,16 @@ pub struct GasConfig {
4545
pub ed25519_batch_verify_cost: LinearGasCost,
4646
/// ed25519 batch signature verification cost (single public key)
4747
pub ed25519_batch_verify_one_pubkey_cost: LinearGasCost,
48-
/// bls12-381 aggregate cost per point (g1)
49-
pub bls12_381_aggregate_g1_per_point: u64,
50-
/// bls12-381 aggregate cost per point (g2)
51-
pub bls12_381_aggregate_g2_per_point: u64,
48+
/// bls12-381 aggregate cost (g1)
49+
pub bls12_381_aggregate_g1_cost: LinearGasCost,
50+
/// bls12-381 aggregate cost (g2)
51+
pub bls12_381_aggregate_g2_cost: LinearGasCost,
5252
/// bls12-381 hash to g1 cost
5353
pub bls12_381_hash_to_g1_cost: u64,
5454
/// bls12-381 hash to g2 cost
5555
pub bls12_381_hash_to_g2_cost: u64,
5656
/// bls12-381 pairing equality check cost
57-
pub bls12_381_pairing_equality_cost: u64,
58-
/// bls12-381 aggregated pairing equality check cost per point
59-
/// (added on top of the base pairing equality check cost)
60-
pub bls12_381_aggregated_pairing_equality_cost_per_pair: u64,
57+
pub bls12_381_pairing_equality_cost: LinearGasCost,
6158
}
6259

6360
impl Default for GasConfig {
@@ -86,13 +83,20 @@ impl Default for GasConfig {
8683
per_item: 10 * GAS_PER_US,
8784
},
8885
// just assume the production machines have more than 4 cores, so we can half that
89-
bls12_381_aggregate_g1_per_point: 16 * GAS_PER_US / 2,
90-
bls12_381_aggregate_g2_per_point: 33 * GAS_PER_US / 2,
91-
bls12_381_hash_to_g1_cost: 324 * GAS_PER_US,
92-
bls12_381_hash_to_g2_cost: 528 * GAS_PER_US,
93-
// god i wish i was lying
94-
bls12_381_pairing_equality_cost: 1038 * GAS_PER_US,
95-
bls12_381_aggregated_pairing_equality_cost_per_pair: 108 * GAS_PER_US,
86+
bls12_381_aggregate_g1_cost: LinearGasCost {
87+
base: 136 * GAS_PER_US / 2,
88+
per_item: 24 * GAS_PER_US / 2,
89+
},
90+
bls12_381_aggregate_g2_cost: LinearGasCost {
91+
base: 207 * GAS_PER_US / 2,
92+
per_item: 49 * GAS_PER_US / 2,
93+
},
94+
bls12_381_hash_to_g1_cost: 563 * GAS_PER_US,
95+
bls12_381_hash_to_g2_cost: 871 * GAS_PER_US,
96+
bls12_381_pairing_equality_cost: LinearGasCost {
97+
base: 2281 * GAS_PER_US,
98+
per_item: 163 * GAS_PER_US,
99+
},
96100
}
97101
}
98102
}

packages/vm/src/imports.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ pub fn do_bls12_381_aggregate_g1<
278278

279279
let estimated_point_count = (g1s.len() / BLS12_381_G1_POINT_LEN) as u64;
280280
let gas_info = GasInfo::with_cost(
281-
data.gas_config.bls12_381_aggregate_g1_per_point * estimated_point_count,
281+
data.gas_config
282+
.bls12_381_aggregate_g1_cost
283+
.total_cost(estimated_point_count),
282284
);
283285
process_gas_info(data, &mut store, gas_info)?;
284286

@@ -322,7 +324,9 @@ pub fn do_bls12_381_aggregate_g2<
322324

323325
let estimated_point_count = (g2s.len() / BLS12_381_G2_POINT_LEN) as u64;
324326
let gas_info = GasInfo::with_cost(
325-
data.gas_config.bls12_381_aggregate_g2_per_point * estimated_point_count,
327+
data.gas_config
328+
.bls12_381_aggregate_g2_cost
329+
.total_cost(estimated_point_count),
326330
);
327331
process_gas_info(data, &mut store, gas_info)?;
328332

@@ -370,14 +374,14 @@ pub fn do_bls12_381_pairing_equality<
370374
let s = read_region(&memory, s_ptr, BLS12_381_G2_POINT_LEN)?;
371375

372376
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);
377+
378+
let gas_info = GasInfo::with_cost(
379+
// Add one to the `estimated_point_count` since we do not include any pairs in the base
380+
// benchmark, and we always need to add one for the `r` and `s` pair.
381+
data.gas_config
382+
.bls12_381_pairing_equality_cost
383+
.total_cost(estimated_point_count + 1),
384+
);
381385
process_gas_info(data, &mut store, gas_info)?;
382386

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

0 commit comments

Comments
 (0)