Skip to content

Commit 4c6492a

Browse files
committed
Refactor ed25519_batch_verify gas cost
1 parent b96aa96 commit 4c6492a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/vm/src/environment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ pub struct GasConfig {
4242
/// ed25519 signature verification cost
4343
pub ed25519_verify_cost: u64,
4444
/// ed25519 batch signature verification cost
45+
/// This is charged per signature.
4546
pub ed25519_batch_verify_cost: u64,
4647
/// ed25519 batch signature verification cost (single public key)
48+
/// This is charged per signature.
4749
pub ed25519_batch_verify_one_pubkey_cost: u64,
4850
/// bls12-381 aggregate cost per point (g1)
4951
pub bls12_381_aggregate_g1_per_point: u64,

packages/vm/src/imports.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,17 @@ pub fn do_ed25519_batch_verify<
728728
let signatures = decode_sections(&signatures);
729729
let public_keys = decode_sections(&public_keys);
730730

731-
let gas_cost = if public_keys.len() == 1 {
731+
let gas_cost_per_sig = if public_keys.len() == 1 {
732732
data.gas_config.ed25519_batch_verify_one_pubkey_cost
733733
} else {
734734
data.gas_config.ed25519_batch_verify_cost
735-
} * signatures.len() as u64;
736-
let gas_info = GasInfo::with_cost(max(gas_cost, data.gas_config.ed25519_verify_cost));
735+
};
736+
let gas_info = GasInfo::with_cost(max(
737+
// charge for each signature
738+
gas_cost_per_sig * (signatures.len() as u64),
739+
// but ensure we charge something even if there are no signatures
740+
data.gas_config.ed25519_verify_cost,
741+
));
737742
process_gas_info(data, &mut store, gas_info)?;
738743
let result = ed25519_batch_verify(&mut OsRng, &messages, &signatures, &public_keys);
739744
let code = match result {

0 commit comments

Comments
 (0)