Skip to content

Commit abd5b1a

Browse files
authored
Merge pull request #3368 from autonomys/invalid-fp-test
Fix inconsistency of bundle digest generation and add invalid fraud proof integration test
2 parents f5e8b43 + b9e5b63 commit abd5b1a

File tree

4 files changed

+377
-8
lines changed

4 files changed

+377
-8
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use sp_api::ProvideRuntimeApi;
2020
use sp_blockchain::HeaderBackend;
2121
use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode};
2222
use sp_core::H256;
23-
use sp_domains::{BundleProducerElectionApi, DomainsApi};
23+
use sp_domains::{BundleProducerElectionApi, DomainsApi, ExtrinsicDigest};
2424
use sp_externalities::Extensions;
2525
use sp_messenger::MessengerApi;
2626
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor};
2727
use sp_runtime::OpaqueExtrinsic;
28-
use sp_state_machine::{OverlayedChanges, StateMachine, TrieBackend, TrieBackendBuilder};
28+
use sp_state_machine::{LayoutV1, OverlayedChanges, StateMachine, TrieBackend, TrieBackendBuilder};
2929
use sp_trie::{MemoryDB, StorageProof};
3030
use sp_weights::Weight;
3131
use std::borrow::Cow;
@@ -179,7 +179,9 @@ where
179179
.map(|(signer, tx)| {
180180
(
181181
signer,
182-
<DomainBlock::Header as HeaderT>::Hashing::hash_of(&tx),
182+
ExtrinsicDigest::new::<LayoutV1<<DomainBlock::Header as HeaderT>::Hashing>>(
183+
tx.encode(),
184+
),
183185
)
184186
})
185187
.collect();

domains/client/domain-operator/src/domain_block_processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ where
877877
mismatch_type,
878878
bundle_index,
879879
bad_receipt_hash,
880+
false,
880881
)
881882
.map_err(|err| {
882883
sp_blockchain::Error::Application(Box::from(format!(

domains/client/domain-operator/src/fraud_proof.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ where
518518
mismatch_type: BundleMismatchType,
519519
bundle_index: u32,
520520
bad_receipt_hash: Block::Hash,
521+
// Whether allow generate invalid proof against valid ER,
522+
// only used in test
523+
allow_invalid_proof: bool,
521524
) -> Result<FraudProofFor<CBlock, Block::Header>, FraudProofError> {
522525
let consensus_block_hash = local_receipt.consensus_block_hash;
523526
let consensus_block_number = local_receipt.consensus_block_number;
@@ -641,11 +644,12 @@ where
641644
// If the proof is false invalid then validation response should not be Err.
642645
// OR
643646
// If it is true invalid and expected extrinsic index does not match
644-
if (is_true_invalid == validation_response.is_ok())
645-
|| (is_true_invalid
646-
&& validation_response
647-
.as_ref()
648-
.is_err_and(|e| e.extrinsic_index != expected_extrinsic_index))
647+
if !allow_invalid_proof
648+
&& ((is_true_invalid == validation_response.is_ok())
649+
|| (is_true_invalid
650+
&& validation_response
651+
.as_ref()
652+
.is_err_and(|e| e.extrinsic_index != expected_extrinsic_index)))
649653
{
650654
return Err(FraudProofError::InvalidIllegalTxFraudProofExtrinsicIndex {
651655
index: expected_extrinsic_index as usize,

0 commit comments

Comments
 (0)