Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Jan 5, 2024
1 parent 5ea8ee8 commit 2b2c1d1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension {
&self,
_pre_state_root: H256,
_encoded_proof: Vec<u8>,
_verifying_method: &str,
_execution_method: &str,
_call_data: &[u8],
_domain_runtime_code: Vec<u8>,
) -> Option<Vec<u8>> {
Expand Down
8 changes: 4 additions & 4 deletions crates/sp-domains-fraud-proof/src/execution_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ where
.runtime_code()
.map_err(sp_blockchain::Error::RuntimeCode)?;

// TODO: avoid using the String API specified by `proving_method()`
// TODO: avoid using the String API specified by `execution_method()`
// https://github.com/paritytech/substrate/discussions/11095
if let Some((delta, post_delta_root)) = delta_changes {
let delta_backend = create_delta_backend(trie_backend, delta, post_delta_root);
sp_state_machine::prove_execution_on_trie_backend(
&delta_backend,
&mut Default::default(),
&*self.executor,
execution_phase.proving_method(),
execution_phase.execution_method(),
call_data,
&runtime_code,
&mut Default::default(),
Expand All @@ -77,7 +77,7 @@ where
trie_backend,
&mut Default::default(),
&*self.executor,
execution_phase.proving_method(),
execution_phase.execution_method(),
call_data,
&runtime_code,
&mut Default::default(),
Expand Down Expand Up @@ -114,7 +114,7 @@ where
proof,
&mut Default::default(),
&*self.executor,
execution_phase.verifying_method(),
execution_phase.execution_method(),
call_data,
&runtime_code,
)
Expand Down
15 changes: 1 addition & 14 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum ExecutionPhase {

impl ExecutionPhase {
/// Returns the method for generating the proof.
pub fn proving_method(&self) -> &'static str {
pub fn execution_method(&self) -> &'static str {
match self {
// TODO: Replace `DomainCoreApi_initialize_block_with_post_state_root` with `Core_initalize_block`
// Should be a same issue with https://github.com/paritytech/substrate/pull/10922#issuecomment-1068997467
Expand All @@ -42,19 +42,6 @@ impl ExecutionPhase {
}
}

/// Returns the method for verifying the proof.
///
/// The difference with [`Self::proving_method`] is that the return value of verifying method
/// must contain the post state root info so that it can be used to compare whether the
/// result of execution reported in [`FraudProof`] is expected or not.
pub fn verifying_method(&self) -> &'static str {
match self {
Self::InitializeBlock => "DomainCoreApi_initialize_block_with_post_state_root",
Self::ApplyExtrinsic { .. } => "DomainCoreApi_apply_extrinsic_with_post_state_root",
Self::FinalizeBlock => "BlockBuilder_finalize_block",
}
}

/// Returns the post state root for the given execution result.
pub fn decode_execution_result<Header: HeaderT>(
&self,
Expand Down
6 changes: 3 additions & 3 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub trait FraudProofHostFunctions: Send + Sync {
pre_state_root: H256,
// TODO: implement `PassBy` for `sp_trie::StorageProof` in upstream to pass it directly here
encoded_proof: Vec<u8>,
verifying_method: &str,
execution_method: &str,
call_data: &[u8],
domain_runtime_code: Vec<u8>,
) -> Option<Vec<u8>>;
Expand Down Expand Up @@ -467,7 +467,7 @@ where
&self,
pre_state_root: H256,
encoded_proof: Vec<u8>,
verifying_method: &str,
execution_method: &str,
call_data: &[u8],
domain_runtime_code: Vec<u8>,
) -> Option<Vec<u8>> {
Expand All @@ -486,7 +486,7 @@ where
proof,
&mut Default::default(),
self.executor.as_ref(),
verifying_method,
execution_method,
call_data,
&runtime_code,
)
Expand Down
4 changes: 2 additions & 2 deletions crates/sp-domains-fraud-proof/src/runtime_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait FraudProofRuntimeInterface {
&mut self,
pre_state_root: H256,
encoded_proof: Vec<u8>,
verifying_method: &str,
execution_method: &str,
call_data: &[u8],
domain_runtime_code: Vec<u8>,
) -> Option<Vec<u8>> {
Expand All @@ -49,7 +49,7 @@ pub trait FraudProofRuntimeInterface {
.execution_proof_check(
pre_state_root,
encoded_proof,
verifying_method,
execution_method,
call_data,
domain_runtime_code,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
let execution_result = fraud_proof_runtime_interface::execution_proof_check(
pre_state_root,
proof.encode(),
execution_phase.verifying_method(),
execution_phase.execution_method(),
call_data.as_ref(),
domain_runtime_code,
)
Expand Down
4 changes: 2 additions & 2 deletions domains/client/domain-operator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ async fn test_finalize_block_proof_creation_and_verification_should_work() {
}

#[tokio::test(flavor = "multi_thread")]
async fn test_false_invalid_state_transition_proof_is_rejected() {
async fn test_bad_invalid_state_transition_proof_is_rejected() {
let directory = TempDir::new().expect("Must be able to create temporary directory");

let mut builder = sc_cli::LoggerBuilder::new("");
Expand Down Expand Up @@ -865,7 +865,7 @@ async fn test_false_invalid_state_transition_proof_is_rejected() {

// We get the receipt of target bundle
let (slot, bundle) = ferdie.produce_slot_and_wait_for_bundle_submission().await;
let valid_receipt = bundle.unwrap().sealed_header.header.receipt;
let valid_receipt = bundle.unwrap().into_receipt();
assert_eq!(valid_receipt.execution_trace.len(), 4);
let valid_receipt_hash = valid_receipt.hash::<BlakeTwo256>();

Expand Down

0 comments on commit 2b2c1d1

Please sign in to comment.