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

Revamp invalid state transition proof #2072

Merged
merged 10 commits into from
Oct 19, 2023
Merged

Conversation

NingLin-P
Copy link
Member

@NingLin-P NingLin-P commented Oct 6, 2023

close #1890

The first 2 commits are picked from #1983, depends on which PRs merge first, the latter one should remove these commits.

This PR revamps the invalid state transition proof based on the v2 design, notable changes compared to v1:

  • Many fields of InvalidStateTransitionProof are replaced by the field bad_receipt_hash, the bad receipt is retrieved from the consensus chain and its data is used instead during the verification
  • Add the runtime_code_with_proof field to the fraud proof which contains the domain runtime code along with the storage proof
  • The call data of the execution proof are provided by the fraud proof directly and verified against the bad receipt
  • Introduce the DomainBlock config item to pallet-domains, which is used to construct the domain block header during the invalid state transition fraud proof
  • Add host functions for getting the domain runtime code and checking the execution proof

Code contributor checklist:

@NingLin-P NingLin-P force-pushed the revamp-invalid-state-proof branch from 6c1be67 to 2f92af4 Compare October 7, 2023 14:35
@NingLin-P NingLin-P force-pushed the revamp-invalid-state-proof branch 2 times, most recently from 8b93038 to c500f7d Compare October 9, 2023 07:51
@NingLin-P NingLin-P marked this pull request as draft October 12, 2023 15:13
Signed-off-by: linning <linningde25@gmail.com>
It is used to construct the domain block header during the verification of the invalid state
transtion in the upcoming commits, this commit also removed the DomainNumber config
item since it can be derived from DomainBlock, but the DomainHash is still needed for
converting DomainHash to/from H256.

Signed-off-by: linning <linningde25@gmail.com>
… execution proof

They are used in the verification of the invalid state transition fraud proof

Signed-off-by: linning <linningde25@gmail.com>
Mainly remove fields that already exist in the bad receipt

Signed-off-by: linning <linningde25@gmail.com>
…nsus runtime

Signed-off-by: linning <linningde25@gmail.com>
Since we don't need to verify this fraud proof in the client side anymore

Signed-off-by: linning <linningde25@gmail.com>
Signed-off-by: linning <linningde25@gmail.com>
@NingLin-P NingLin-P force-pushed the revamp-invalid-state-proof branch from c500f7d to cb77a6f Compare October 16, 2023 13:54
@NingLin-P NingLin-P marked this pull request as ready for review October 16, 2023 13:55
@NingLin-P
Copy link
Member Author

This PR is updated according to the host function approach, PTAL thanks!

Copy link
Member

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

Make sense. Left some questions and nits.

crates/pallet-domains/src/lib.rs Outdated Show resolved Hide resolved
crates/pallet-domains/src/block_tree.rs Outdated Show resolved Hide resolved
crates/pallet-domains/src/lib.rs Outdated Show resolved Hide resolved
crates/sp-domains-fraud-proof/src/host_functions.rs Outdated Show resolved Hide resolved
crates/sp-domains/src/lib.rs Outdated Show resolved Hide resolved
crates/sp-domains/src/fraud_proof.rs Show resolved Hide resolved
@NingLin-P NingLin-P force-pushed the revamp-invalid-state-proof branch from bd1398b to bc81164 Compare October 18, 2023 15:53
Copy link
Member

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

Make sense to me. Left some question on Storage Proof generation and Verification

crates/pallet-domains/src/lib.rs Outdated Show resolved Hide resolved
/// Gnenerate a proof-of-inclusion of the value at the given `input[index]`
///
/// Return `None` if the given `index` out of range or fail to generate the proof
pub fn generate_proof<Layout: TrieLayout>(input: &[Vec<u8>], index: u32) -> Option<Vec<Vec<u8>>> {
Copy link
Member

Choose a reason for hiding this comment

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

I missed this earlier. Shouldn't this return a Storage Proof type instead. It would be nice to have that instead of returning some bare vectors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Vec<Vec<u8>> is what returned by trie_db::proof::generate_proof, we can't use StorageProof unless they can be verified in the same way.

}

/// Verify the proof-of-inclusion of the `data` at the `index` of the merkle root `root`
pub fn verify_proof<Layout>(
Copy link
Member

@vedhavyas vedhavyas Oct 18, 2023

Choose a reason for hiding this comment

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

There is already a storage proof verification in the verification module. We should use that instead. Ideally, we should call it Storage Proof Provider that can generate proofs and verify proofs

Copy link
Member Author

Choose a reason for hiding this comment

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

I have explored this direction a bit but verify_and_get_value doesn't work directly, while both approaches use trie-db under the hook, there must be some differences between generating StorageProof and trie_db::proof::generate_proof (the later is used to generating proof-of-inclusion specifically).

I will leave a TODO for now, let me if you have a better idea.

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 should be generated something similart to - https://github.com/subspace/subspace/blob/main/crates/pallet-domains/src/tests.rs#L829

Anyway leave a TODO and we can revisit this

.map_err(|_| FraudProofError::InvalidStateRootType)?;

let digest = Digest::default();
let digest = self.client.runtime_api().block_digest(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.

I'm sorry to confuse you on the digests. I have a question here. The digest you are fetching here is the post block digest. So it includes all the digest items that were added during the state transition and on_finalization. So the digests might not the same digests that were passed during the new block initialization then, correct ? So we may be adding the digest logs that will added in the later execution in the intialization itself. Thoughts @NingLin-P

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I took a closer look. I think the first version of this PR is fine, namely only including the consensus_block_info digest which is the only inherent digest and doesn't need the digest storage proof at all.

For ApplyExtrinsic and FinalizeBlock, the necessary extrinsic will be executed before generating the execution proof (see prepare_storage_changes_before and prepare_storage_changes_before_finalize_block) so the digests emitted during block execution/finalization will be included in the proof properly.

One last question about "there are digests from frontier we should consider here that are missing", do you mean the digest emitted during block execution/finalization or the inherent digest?

…nd some cleanup

Signed-off-by: linning <linningde25@gmail.com>
}

/// Verify the proof-of-inclusion of the `data` at the `index` of the merkle root `root`
pub fn verify_proof<Layout>(
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 should be generated something similart to - https://github.com/subspace/subspace/blob/main/crates/pallet-domains/src/tests.rs#L829

Anyway leave a TODO and we can revisit this

@NingLin-P NingLin-P added this pull request to the merge queue Oct 19, 2023
Merged via the queue into main with commit 5d06efe Oct 19, 2023
10 checks passed
@NingLin-P NingLin-P deleted the revamp-invalid-state-proof branch October 19, 2023 09:23
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.

Invalid state transition fraud proof for ER::execution_trace
2 participants