Skip to content

Commit 470a02c

Browse files
committed
Add fraud proof pre-check benchmark
Signed-off-by: linning <[email protected]>
1 parent 617c426 commit 470a02c

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

crates/pallet-domains/src/benchmarking.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,60 @@ mod benchmarks {
10361036
}
10371037
}
10381038

1039+
#[benchmark]
1040+
fn fraud_proof_pre_check() {
1041+
let domain_id = register_domain::<T>();
1042+
let (_, operator_id) =
1043+
register_helper_operator::<T>(domain_id, T::MinNominatorStake::get());
1044+
1045+
let mut target_receipt_hash = None;
1046+
let mut receipt =
1047+
BlockTree::<T>::get::<_, DomainBlockNumberFor<T>>(domain_id, Zero::zero())
1048+
.and_then(BlockTreeNodes::<T>::get)
1049+
.expect("genesis receipt must exist")
1050+
.execution_receipt;
1051+
for i in 1u32..=4u32 {
1052+
let consensus_block_number = i.into();
1053+
let domain_block_number = i.into();
1054+
1055+
// Run to `block_number`
1056+
run_to_block::<T>(
1057+
consensus_block_number,
1058+
frame_system::Pallet::<T>::block_hash(consensus_block_number - One::one()),
1059+
);
1060+
1061+
// Submit a bundle with the receipt of the last block
1062+
let bundle = dummy_opaque_bundle(domain_id, operator_id, receipt);
1063+
assert_ok!(Domains::<T>::submit_bundle(
1064+
DomainOrigin::ValidatedUnsigned.into(),
1065+
bundle
1066+
));
1067+
1068+
// Create ER for the above bundle
1069+
let head_receipt_number = HeadReceiptNumber::<T>::get(domain_id);
1070+
let parent_domain_block_receipt = BlockTree::<T>::get(domain_id, head_receipt_number)
1071+
.expect("parent receipt must exist");
1072+
receipt = ExecutionReceipt::dummy::<DomainHashingFor<T>>(
1073+
consensus_block_number,
1074+
frame_system::Pallet::<T>::block_hash(consensus_block_number),
1075+
domain_block_number,
1076+
parent_domain_block_receipt,
1077+
);
1078+
if i == 3 {
1079+
target_receipt_hash.replace(receipt.hash::<DomainHashingFor<T>>());
1080+
}
1081+
}
1082+
assert_eq!(Domains::<T>::head_receipt_number(domain_id), 3u32.into());
1083+
1084+
// Construct fraud proof that target the ER at block #3
1085+
let fraud_proof = FraudProof::dummy_fraud_proof(domain_id, target_receipt_hash.unwrap());
1086+
1087+
#[block]
1088+
{
1089+
assert_ok!(Domains::<T>::validate_fraud_proof(&fraud_proof));
1090+
}
1091+
}
1092+
10391093
fn register_runtime<T: Config>() -> RuntimeId {
10401094
let genesis_storage = include_bytes!("../res/evm-domain-genesis-storage").to_vec();
10411095
let runtime_id = NextRuntimeId::<T>::get();

crates/pallet-domains/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,19 @@ impl<T: Config> Pallet<T> {
26472647
})?
26482648
}
26492649
#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
2650-
FraudProofVariant::Dummy => {}
2650+
FraudProofVariant::Dummy => {
2651+
// Almost every fraud proof (except `InvalidDomainBlockHash` fraud proof) need to call
2652+
// `get_domain_runtime_code_for_receipt` thus we include this part in the benchmark of
2653+
// the dummy fraud proof.
2654+
//
2655+
// NOTE: the dummy fraud proof's `maybe_domain_runtime_code_proof` is `None` thus
2656+
// this proof's verification is not included in the benchmark here.
2657+
let _ = Self::get_domain_runtime_code_for_receipt(
2658+
domain_id,
2659+
&bad_receipt,
2660+
fraud_proof.maybe_domain_runtime_code_proof.clone(),
2661+
)?;
2662+
}
26512663
}
26522664

26532665
// The priority of fraud proof is determined by how many blocks left before the bad ER

0 commit comments

Comments
 (0)