Skip to content

Commit 33cc825

Browse files
committed
Generate and apply the fraud proof verification weights
Signed-off-by: linning <[email protected]>
1 parent fed07b5 commit 33cc825

File tree

3 files changed

+136
-1
lines changed

3 files changed

+136
-1
lines changed

crates/pallet-domains/src/extensions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use frame_support::weights::Weight;
88
use frame_system::pallet_prelude::RuntimeCallFor;
99
use parity_scale_codec::{Decode, Encode};
1010
use scale_info::prelude::fmt;
11+
use sp_domains_fraud_proof::weights::fraud_proof_verification_weights;
1112
use sp_domains_fraud_proof::InvalidTransactionCode;
1213
use sp_runtime::impl_tx_ext_default;
1314
use sp_runtime::traits::{
@@ -183,8 +184,9 @@ where
183184
Some(DomainsCall::submit_bundle { .. }) => {
184185
<Runtime as Config>::WeightInfo::validate_submit_bundle()
185186
}
186-
Some(DomainsCall::submit_fraud_proof { .. }) => {
187+
Some(DomainsCall::submit_fraud_proof { fraud_proof }) => {
187188
<Runtime as Config>::WeightInfo::fraud_proof_pre_check()
189+
.saturating_add(fraud_proof_verification_weights::<_, _, _, _>(fraud_proof))
188190
}
189191
Some(DomainsCall::submit_receipt { .. }) => {
190192
<Runtime as Config>::WeightInfo::validate_singleton_receipt()

crates/sp-domains-fraud-proof/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod storage_proof;
1616
#[cfg(test)]
1717
mod tests;
1818
pub mod verification;
19+
pub mod weights;
1920

2021
#[cfg(not(feature = "std"))]
2122
extern crate alloc;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
use crate::fraud_proof::{FraudProof, FraudProofVariant};
2+
use sp_domains::InvalidBundleType;
3+
use sp_runtime::traits::Header as HeaderT;
4+
use sp_weights::Weight;
5+
6+
pub fn fraud_proof_verification_weights<Number, Hash, DomainHeader: HeaderT, MmrHash>(
7+
fp: &FraudProof<Number, Hash, DomainHeader, MmrHash>,
8+
) -> Weight {
9+
let mut weight = match &fp.proof {
10+
FraudProofVariant::InvalidStateTransition(_) => {
11+
invalid_state_transition_proof_verification()
12+
}
13+
FraudProofVariant::ValidBundle(_) => valid_bundle_proof_verification(),
14+
FraudProofVariant::InvalidExtrinsicsRoot(_) => invalid_domain_extrinsics_root_fraud_proof(),
15+
FraudProofVariant::InvalidDomainBlockHash(_) => {
16+
invalid_domain_block_hash_fraud_proof_verification()
17+
}
18+
FraudProofVariant::InvalidBlockFees(_) => invalid_block_fees_fraud_proof_verification(),
19+
FraudProofVariant::InvalidTransfers(_) => invalid_transfers_fraud_proof_verification(),
20+
FraudProofVariant::InvalidBundles(p) => match p.invalid_bundle_type {
21+
InvalidBundleType::UndecodableTx(_) => {
22+
invalid_bundle_undecodable_tx_fraud_proof_verification()
23+
}
24+
InvalidBundleType::OutOfRangeTx(_) => {
25+
invalid_bundle_out_of_range_tx_fraud_proof_verification()
26+
}
27+
InvalidBundleType::IllegalTx(_) => invalid_bundle_illegal_tx_fraud_proof_verification(),
28+
InvalidBundleType::InvalidXDM(_) => {
29+
invalid_bundle_invalid_xdm_fraud_proof_verification()
30+
}
31+
InvalidBundleType::InherentExtrinsic(_) => {
32+
invalid_bundle_inherent_extrinsic_fraud_proof_verification()
33+
}
34+
InvalidBundleType::InvalidBundleWeight => {
35+
invalid_bundle_weight_fraud_proof_verification()
36+
}
37+
},
38+
#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
39+
FraudProofVariant::Dummy => Weight::zero(),
40+
};
41+
if fp.maybe_mmr_proof.is_some() {
42+
weight = weight.saturating_add(consensus_state_root_mmr_proof_verification());
43+
}
44+
if fp.maybe_domain_runtime_code_proof.is_some() {
45+
weight = weight.saturating_add(domain_runtime_code_proof_verification());
46+
}
47+
weight
48+
}
49+
50+
fn consensus_state_root_mmr_proof_verification() -> Weight {
51+
// Verification time is around 2_022_700 pico seconds
52+
// Generated by the `mmr_proof_and_runtime_code_proof_verification` bench
53+
Weight::from_parts(2_022_700, 0)
54+
}
55+
56+
fn domain_runtime_code_proof_verification() -> Weight {
57+
// Verification time is around 2_022_700 pico seconds
58+
// Generated by the `mmr_proof_and_runtime_code_proof_verification` bench
59+
Weight::from_parts(925_650_000, 0)
60+
}
61+
62+
fn invalid_state_transition_proof_verification() -> Weight {
63+
// Verification time is around 359_040_000 pico seconds
64+
// Generated by the `invalid_state_transition_proof_verification` bench
65+
Weight::from_parts(359_040_000, 0)
66+
}
67+
68+
fn valid_bundle_proof_verification() -> Weight {
69+
// Verification time is around 754_330_000 pico seconds
70+
// Generated by the `valid_bundle_proof_verification` bench
71+
Weight::from_parts(754_330_000, 0)
72+
}
73+
74+
fn invalid_domain_extrinsics_root_fraud_proof() -> Weight {
75+
// Verification time is around 1_495_800_000 pico seconds
76+
// Generated by the `invalid_domain_extrinsics_root_fraud_proof` bench
77+
Weight::from_parts(1_495_800_000, 0)
78+
}
79+
80+
fn invalid_domain_block_hash_fraud_proof_verification() -> Weight {
81+
// Verification time is around 5_929_100 pico seconds
82+
// Generated by the `invalid_domain_block_hash_fraud_proof_verification` bench
83+
Weight::from_parts(5_929_100, 0)
84+
}
85+
86+
fn invalid_block_fees_fraud_proof_verification() -> Weight {
87+
// Verification time is around 746_860_000 pico seconds
88+
// Generated by the `invalid_block_fees_fraud_proof_verification` bench
89+
Weight::from_parts(746_860_000, 0)
90+
}
91+
92+
fn invalid_transfers_fraud_proof_verification() -> Weight {
93+
// Verification time is around 744_740_000 pico seconds
94+
// Generated by the `invalid_transfers_fraud_proof_verification` bench
95+
Weight::from_parts(744_740_000, 0)
96+
}
97+
98+
fn invalid_bundle_undecodable_tx_fraud_proof_verification() -> Weight {
99+
// Verification time is around 751_320_000 pico seconds
100+
// Generated by the `invalid_bundle_undecodable_tx_fraud_proof_verification` bench
101+
Weight::from_parts(751_320_000, 0)
102+
}
103+
104+
fn invalid_bundle_out_of_range_tx_fraud_proof_verification() -> Weight {
105+
// Verification time is around 745_380_000 pico seconds
106+
// Generated by the `invalid_bundle_out_of_range_tx_fraud_proof_verification` bench
107+
Weight::from_parts(745_380_000, 0)
108+
}
109+
110+
fn invalid_bundle_illegal_tx_fraud_proof_verification() -> Weight {
111+
// Verification time is around 198_720_000 pico seconds
112+
// Generated by the `invalid_bundle_out_of_range_tx_fraud_proof_verification` bench
113+
Weight::from_parts(198_720_000, 0)
114+
}
115+
116+
fn invalid_bundle_invalid_xdm_fraud_proof_verification() -> Weight {
117+
// Verification time is around 750_950_000 pico seconds
118+
// Generated by the `invalid_bundle_invalid_xdm_fraud_proof_verification` bench
119+
Weight::from_parts(750_950_000, 0)
120+
}
121+
122+
fn invalid_bundle_inherent_extrinsic_fraud_proof_verification() -> Weight {
123+
// Verification time is around 746_340_000 pico seconds
124+
// Generated by the `invalid_bundle_inherent_extrinsic_fraud_proof_verification` bench
125+
Weight::from_parts(746_340_000, 0)
126+
}
127+
128+
fn invalid_bundle_weight_fraud_proof_verification() -> Weight {
129+
// Verification time is around 761_690_000 pico seconds
130+
// Generated by the `invalid_bundle_weight_fraud_proof_verification` bench
131+
Weight::from_parts(761_690_000, 0)
132+
}

0 commit comments

Comments
 (0)