Skip to content

Commit

Permalink
Merge pull request #3368 from autonomys/invalid-fp-test
Browse files Browse the repository at this point in the history
Fix inconsistency of bundle digest generation and add invalid fraud proof integration test
  • Loading branch information
NingLin-P authored Feb 6, 2025
2 parents f5e8b43 + b9e5b63 commit abd5b1a
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 8 deletions.
8 changes: 5 additions & 3 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode};
use sp_core::H256;
use sp_domains::{BundleProducerElectionApi, DomainsApi};
use sp_domains::{BundleProducerElectionApi, DomainsApi, ExtrinsicDigest};
use sp_externalities::Extensions;
use sp_messenger::MessengerApi;
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor};
use sp_runtime::OpaqueExtrinsic;
use sp_state_machine::{OverlayedChanges, StateMachine, TrieBackend, TrieBackendBuilder};
use sp_state_machine::{LayoutV1, OverlayedChanges, StateMachine, TrieBackend, TrieBackendBuilder};
use sp_trie::{MemoryDB, StorageProof};
use sp_weights::Weight;
use std::borrow::Cow;
Expand Down Expand Up @@ -179,7 +179,9 @@ where
.map(|(signer, tx)| {
(
signer,
<DomainBlock::Header as HeaderT>::Hashing::hash_of(&tx),
ExtrinsicDigest::new::<LayoutV1<<DomainBlock::Header as HeaderT>::Hashing>>(
tx.encode(),
),
)
})
.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ where
mismatch_type,
bundle_index,
bad_receipt_hash,
false,
)
.map_err(|err| {
sp_blockchain::Error::Application(Box::from(format!(
Expand Down
14 changes: 9 additions & 5 deletions domains/client/domain-operator/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ where
mismatch_type: BundleMismatchType,
bundle_index: u32,
bad_receipt_hash: Block::Hash,
// Whether allow generate invalid proof against valid ER,
// only used in test
allow_invalid_proof: bool,
) -> Result<FraudProofFor<CBlock, Block::Header>, FraudProofError> {
let consensus_block_hash = local_receipt.consensus_block_hash;
let consensus_block_number = local_receipt.consensus_block_number;
Expand Down Expand Up @@ -641,11 +644,12 @@ where
// If the proof is false invalid then validation response should not be Err.
// OR
// If it is true invalid and expected extrinsic index does not match
if (is_true_invalid == validation_response.is_ok())
|| (is_true_invalid
&& validation_response
.as_ref()
.is_err_and(|e| e.extrinsic_index != expected_extrinsic_index))
if !allow_invalid_proof
&& ((is_true_invalid == validation_response.is_ok())
|| (is_true_invalid
&& validation_response
.as_ref()
.is_err_and(|e| e.extrinsic_index != expected_extrinsic_index)))
{
return Err(FraudProofError::InvalidIllegalTxFraudProofExtrinsicIndex {
index: expected_extrinsic_index as usize,
Expand Down
Loading

0 comments on commit abd5b1a

Please sign in to comment.