Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OutOfRangeTx variant of Invalid bundle fraud proof #2039

Closed
wants to merge 9 commits into from

Conversation

ParthDesai
Copy link
Contributor

Description

This PR implements OutOfRangeTx fraud proof as one variant of Invalid bundle fraud proof. It introduces generation and verification of it.

Commits are organized as follows:
1st commit introduces a rough version of the generation and verification in which we do not take into account the bad receipt.
2nd commit adds runtime api to get the execution receipt from the hash (this is used to get the bad receipt and its parent receipt in the verification).
3rd commit utilises the runtime api introduced in 2nd commit to query the bad receipt and its parent for subsequent verification.
4th commit integrates the verifier in the subspace service.
5th commit remove todo that was in place for returning bad receipt hash.
6th commit adds different consensus block hash containing ER and bundle.
7th commit adds test for the generation and verification + some changes in test runtime.
8th commit merges main into this branch.

Code contributor checklist:

@nazar-pc
Copy link
Member

nazar-pc commented Oct 3, 2023

I interrupted CI, Windows job was running for 4 hours 51 minutes, looks like it got stuck there.

UPD: Restarted, looks like issues with networking tests: #2045

Copy link
Member

@NingLin-P NingLin-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good in general, but this PR has a lot of code duplicated/conflicted with #1983 and #1995, would prefer to merge them first.

Comment on lines 196 to 197
pub consensus_block_hash: Hash,
pub parent_domain_block_hash: DomainHash,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need these 2 fields since bad_receipt already contains them.

Comment on lines +256 to 259
MissingInvalidBundleEntry(
MissingInvalidBundleEntryFraudProof<Number, Hash, DomainNumber, DomainHash>,
),
ValidAsInvalid(ValidAsInvalidBundleEntryFraudProof),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "missing" implies that invalid bundle is missing from somewhere, but we don't have the context about "somewhere" here, would be great to avoid using it. FYI #1995 uses TrueInvalid and FalseInvalid to replace these 2 items.

RuntimeApiLight::new(self.executor.clone(), domain_runtime_code.into());

match additional_data {
MissingBundleAdditionalData::OutOfRangeTx { extrinsic_index } => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to move the following to a dedicated function, non-blocker.

Comment on lines -754 to +757
Block,
ParentChainBlock,
>(&*self.client, consensus_block_hash)?
let local_receipt = crate::aux_schema::load_execution_receipt::<_, Block, CBlock>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change ParentChainBlock to CBlock? although it is also correct.

let tx_range = self
.consensus_client
.runtime_api()
.domain_tx_range(*consensus_block_hash, *domain_id)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we are using a different consensus_block_hash for this runtime API:

  • In the block-preprocessor, we are using the consensus block that derives the under constructing domain block
  • In the domain-bundle-proposer, we are using the best consensus block hash
  • Here, we are using the consensus block hash of the ER

Although it is okay since dynamic tx-range will be deprecated, plz add some comments to explain why it is okay and won't lead to non-deterministic results and TODO such that when dynamic tx-range is deprecated we should use a constant tx-range value.

.vrf_hash(),
);

let parent_domain_block_hash = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_within_tx_range is a stateless api so it is okay to use the default value of domain_block_hash cc @vedhavyas

Comment on lines +199 to +200
pub opaque_bundle_with_proof:
OpaqueBundleWithProof<Number, Hash, DomainNumber, DomainHash, Balance>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #1995 we don't need to include the whole bundle in the fraud proof, plz take a look at the PR description.

Comment on lines 472 to 477
sp_api::decl_runtime_apis! {
/// API related to execution receipts stored in runtime
pub trait ExecutionReceiptApi<DomainNumber: Encode + Decode, DomainHash: Encode + Decode> {
fn get_execution_receipt_by_hash(hash: ReceiptHash) -> Option<ExecutionReceipt<NumberFor<Block>, Block::Hash, DomainNumber, DomainHash, Balance>>;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this runtime api can fit into DomainsApi and perhaps just get_execution_receipt or execution_receipt cc @vedhavyas

Comment on lines 126 to 128
if maybe_target_invalid_bundle.is_some() {
let target_invalid_bundle = maybe_target_invalid_bundle
.expect("already checked for None in if condition above; qed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if let Some(target_invalid_bundle) = maybe_target_invalid_bundle {
    ...
}

Comment on lines 237 to 238
consensus_block_incl_er,
consensus_block_incl_bundle,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fraud proof is targetting an invalid ER, consensus_block_incl_bundle should be ER::consensus_block_hash and why do we need consensus_block_incl_er?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay to use the best consensus hash to get the bad receipt, because the fraud proof is included in the next consensus block that builds on top of the best consensus block so the fraud proof should be verified against the best consensus block, if the bad receipt don't exist here which means the bad receipt is already pruned or is in other forks, in both cases the fraud proof should be considered as invalid.

@ParthDesai
Copy link
Contributor Author

Look good in general, but this PR has a lot of code duplicated/conflicted with #1983 and #1995, would prefer to merge them first.

cool. I will handle this PR after those two are merged.

@ParthDesai
Copy link
Contributor Author

Closing in favor of #2136

@ParthDesai ParthDesai closed this Oct 26, 2023
@ParthDesai ParthDesai deleted the draft-tx-out-of-range branch February 27, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants