Skip to content

Commit

Permalink
use correct error, update comment, and remove unneeded check in the t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
vedhavyas committed Oct 17, 2023
1 parent d6f7bbf commit a9cbb81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
6 changes: 4 additions & 2 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ mod pallet {
DescendantsOfFraudulentERNotPruned,
/// Invalid fraud proof since total rewards are not mismatched.
InvalidTotalRewardsFraudProof(sp_domains::verification::VerificationError),
/// Invalid fraud proof since domain block hash is not mismatched.
/// Invalid domain block hash fraud proof.
InvalidDomainBlockHashFraudProof(sp_domains::verification::VerificationError),
/// Invalid domain extrinsic fraud proof
InvalidExtrinsicRootFraudProof(sp_domains::verification::VerificationError),
Expand All @@ -599,6 +599,8 @@ mod pallet {
FailedToGetDomainTimestampExtrinsic,
/// Received invalid Verification info from host function.
ReceivedInvalidVerificationInfo,
/// Parent receipt not found.
ParentReceiptNotFound,
}

impl<T> From<FraudProofError> for Error<T> {
Expand Down Expand Up @@ -1532,7 +1534,7 @@ impl<T: Config> Pallet<T> {
}) => {
let parent_receipt =
DomainBlocks::<T>::get(bad_receipt.parent_domain_block_receipt_hash)
.ok_or(FraudProofError::BadReceiptNotFound)?
.ok_or(FraudProofError::ParentReceiptNotFound)?
.execution_receipt;
verify_invalid_domain_block_hash_fraud_proof::<
T::Block,
Expand Down
30 changes: 10 additions & 20 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,25 +945,24 @@ fn test_invalid_domain_block_hash_fraud_proof() {

let bad_receipt_at = 8;
let mut domain_block = get_block_tree_node_at::<Test>(domain_id, bad_receipt_at).unwrap();

let bad_receipt_hash = domain_block.execution_receipt.hash();
let (fraud_proof, root) = generate_invalid_domain_block_hash_fraud_proof::<Test>(
domain_id,
bad_receipt_hash,
Digest::default(),
);
let (root, digest_storage_proof) =
generate_invalid_domain_block_hash_fraud_proof::<Test>(Digest::default());
domain_block.execution_receipt.final_state_root = root;
domain_block.execution_receipt.domain_block_hash = H256::random();
let bad_receipt_hash = domain_block.execution_receipt.hash();
DomainBlocks::<Test>::insert(bad_receipt_hash, domain_block);
let fraud_proof = FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof {
domain_id,
bad_receipt_hash,
digest_storage_proof,
});
assert_ok!(Domains::validate_fraud_proof(&fraud_proof),);
});
}

fn generate_invalid_domain_block_hash_fraud_proof<T: Config>(
domain_id: DomainId,
bad_receipt_hash: ReceiptHash,
digest: Digest,
) -> (FraudProof<BlockNumberFor<T>, T::Hash>, T::Hash) {
) -> (T::Hash, StorageProof) {
let digest_storage_key = sp_domains::fraud_proof::system_digest_final_key();
let mut root = T::Hash::default();
let mut mdb = PrefixedMemoryDB::<T::Hashing>::default();
Expand All @@ -973,16 +972,7 @@ fn generate_invalid_domain_block_hash_fraud_proof<T: Config>(
};

let backend = TrieBackendBuilder::new(mdb, root).build();
let (root, digest_storage_proof) =
storage_proof_for_key::<T, _>(backend, StorageKey(digest_storage_key));
(
FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof {
domain_id,
bad_receipt_hash,
digest_storage_proof,
}),
root,
)
storage_proof_for_key::<T, _>(backend, StorageKey(digest_storage_key))
}

#[test]
Expand Down
3 changes: 0 additions & 3 deletions domains/client/domain-operator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@ async fn test_invalid_domain_block_hash_proof_creation() {

// When the domain node operator process the primary block that contains the `bad_submit_bundle_tx`,
// it will generate and submit a fraud proof
let mut fraud_proof_submitted = false;
while let Some(ready_tx_hash) = import_tx_stream.next().await {
let ready_tx = ferdie
.transaction_pool
Expand All @@ -1078,13 +1077,11 @@ async fn test_invalid_domain_block_hash_proof_creation() {
if let FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof { .. }) =
*fraud_proof
{
fraud_proof_submitted = true;
break;
}
}
}

assert!(fraud_proof_submitted, "Fraud proof must be submitted");
// Produce a consensus block that contains the fraud proof, the fraud proof wil be verified on
// on the runtime itself
ferdie.produce_blocks(1).await.unwrap();
Expand Down

0 comments on commit a9cbb81

Please sign in to comment.