Fix modexp, update tests, update berlin chainspec (#267)
This commit is contained in:
parent
fb9699d8e1
commit
d8ce175846
@ -115,8 +115,10 @@
|
|||||||
"name": "modexp",
|
"name": "modexp",
|
||||||
"activate_at": "0x00",
|
"activate_at": "0x00",
|
||||||
"pricing": {
|
"pricing": {
|
||||||
"modexp": {
|
"0": {
|
||||||
"divisor": 20
|
"price": {
|
||||||
|
"modexp2565": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,106 +201,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000a": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g1_add",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 600
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000b": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g1_mul",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 12000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000c": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g1_multiexp",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_g1_multiexp": {
|
|
||||||
"base": 12000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000d": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g2_add",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 4500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000e": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g2_mul",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 55000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"000000000000000000000000000000000000000f": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_g2_multiexp",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_g2_multiexp": {
|
|
||||||
"base": 55000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"0000000000000000000000000000000000000010": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_pairing",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_pairing": {
|
|
||||||
"base": 115000,
|
|
||||||
"pair": 23000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"0000000000000000000000000000000000000011": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_fp_to_g1",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 5500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"0000000000000000000000000000000000000012": {
|
|
||||||
"builtin": {
|
|
||||||
"name": "bls12_381_fp2_to_g2",
|
|
||||||
"activate_at": "0",
|
|
||||||
"pricing": {
|
|
||||||
"bls12_const_operations": {
|
|
||||||
"price": 110000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit f55f344ad25cb97ebf4f3d72eca7a263aabde818
|
Subproject commit 1508126ea04cd61495b60db2f036ac823de274b1
|
@ -260,7 +260,7 @@ impl Pricer for Modexp2565Pricer {
|
|||||||
}
|
}
|
||||||
bit_no -= 1;
|
bit_no -= 1;
|
||||||
}
|
}
|
||||||
0
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_multiplication_complexity(base_len: u64, modulus_len: u64) -> f64 {
|
fn calculate_multiplication_complexity(base_len: u64, modulus_len: u64) -> f64 {
|
||||||
@ -283,17 +283,21 @@ impl Pricer for Modexp2565Pricer {
|
|||||||
|
|
||||||
let (base_len, exp_len, exp_low, mod_len) = ModexpPricer::parse_input(input);
|
let (base_len, exp_len, exp_low, mod_len) = ModexpPricer::parse_input(input);
|
||||||
|
|
||||||
if let Some(cost) = ModexpPricer::check_input_boundaries(&base_len, &exp_len, &mod_len) {
|
let cost = if let Some(cost) =
|
||||||
return cost;
|
ModexpPricer::check_input_boundaries(&base_len, &exp_len, &mod_len)
|
||||||
}
|
{
|
||||||
|
cost
|
||||||
|
} else {
|
||||||
let (base_len, exp_len, mod_len) =
|
let (base_len, exp_len, mod_len) =
|
||||||
(base_len.low_u64(), exp_len.low_u64(), mod_len.low_u64());
|
(base_len.low_u64(), exp_len.low_u64(), mod_len.low_u64());
|
||||||
|
|
||||||
let multiplication_complexity = calculate_multiplication_complexity(base_len, mod_len);
|
let multiplication_complexity = calculate_multiplication_complexity(base_len, mod_len);
|
||||||
let iteration_count = calculate_iteration_count(exp_len, &exp_low);
|
let iteration_count = calculate_iteration_count(exp_len, &exp_low);
|
||||||
let computed = (multiplication_complexity * iteration_count as f64 / 3f64).floor() as u64;
|
let computed =
|
||||||
U256::from(std::cmp::max(200, computed))
|
(multiplication_complexity * iteration_count as f64 / 3f64).floor() as u64;
|
||||||
|
U256::from(computed)
|
||||||
|
};
|
||||||
|
std::cmp::max(U256::from(200), cost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user