From 2b2c1d1b885a2d6d927e1536dc9503c4078c429b Mon Sep 17 00:00:00 2001 From: Parth Desai Date: Fri, 5 Jan 2024 18:48:11 +0400 Subject: [PATCH] address review feedback --- crates/pallet-domains/src/tests.rs | 2 +- .../src/execution_prover.rs | 8 ++++---- crates/sp-domains-fraud-proof/src/fraud_proof.rs | 15 +-------------- .../sp-domains-fraud-proof/src/host_functions.rs | 6 +++--- .../src/runtime_interface.rs | 4 ++-- crates/sp-domains-fraud-proof/src/verification.rs | 2 +- domains/client/domain-operator/src/tests.rs | 4 ++-- 7 files changed, 14 insertions(+), 27 deletions(-) diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index 2103366227..095e4ab887 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -363,7 +363,7 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension { &self, _pre_state_root: H256, _encoded_proof: Vec, - _verifying_method: &str, + _execution_method: &str, _call_data: &[u8], _domain_runtime_code: Vec, ) -> Option> { diff --git a/crates/sp-domains-fraud-proof/src/execution_prover.rs b/crates/sp-domains-fraud-proof/src/execution_prover.rs index 01255bdc1c..c253cc52f9 100644 --- a/crates/sp-domains-fraud-proof/src/execution_prover.rs +++ b/crates/sp-domains-fraud-proof/src/execution_prover.rs @@ -57,7 +57,7 @@ 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); @@ -65,7 +65,7 @@ where &delta_backend, &mut Default::default(), &*self.executor, - execution_phase.proving_method(), + execution_phase.execution_method(), call_data, &runtime_code, &mut Default::default(), @@ -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(), @@ -114,7 +114,7 @@ where proof, &mut Default::default(), &*self.executor, - execution_phase.verifying_method(), + execution_phase.execution_method(), call_data, &runtime_code, ) diff --git a/crates/sp-domains-fraud-proof/src/fraud_proof.rs b/crates/sp-domains-fraud-proof/src/fraud_proof.rs index 552685ea1a..8a8fb5a10a 100644 --- a/crates/sp-domains-fraud-proof/src/fraud_proof.rs +++ b/crates/sp-domains-fraud-proof/src/fraud_proof.rs @@ -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 @@ -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( &self, diff --git a/crates/sp-domains-fraud-proof/src/host_functions.rs b/crates/sp-domains-fraud-proof/src/host_functions.rs index 6e34318070..d887c36c3f 100644 --- a/crates/sp-domains-fraud-proof/src/host_functions.rs +++ b/crates/sp-domains-fraud-proof/src/host_functions.rs @@ -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, - verifying_method: &str, + execution_method: &str, call_data: &[u8], domain_runtime_code: Vec, ) -> Option>; @@ -467,7 +467,7 @@ where &self, pre_state_root: H256, encoded_proof: Vec, - verifying_method: &str, + execution_method: &str, call_data: &[u8], domain_runtime_code: Vec, ) -> Option> { @@ -486,7 +486,7 @@ where proof, &mut Default::default(), self.executor.as_ref(), - verifying_method, + execution_method, call_data, &runtime_code, ) diff --git a/crates/sp-domains-fraud-proof/src/runtime_interface.rs b/crates/sp-domains-fraud-proof/src/runtime_interface.rs index fba4ff1997..8c7823e237 100644 --- a/crates/sp-domains-fraud-proof/src/runtime_interface.rs +++ b/crates/sp-domains-fraud-proof/src/runtime_interface.rs @@ -40,7 +40,7 @@ pub trait FraudProofRuntimeInterface { &mut self, pre_state_root: H256, encoded_proof: Vec, - verifying_method: &str, + execution_method: &str, call_data: &[u8], domain_runtime_code: Vec, ) -> Option> { @@ -49,7 +49,7 @@ pub trait FraudProofRuntimeInterface { .execution_proof_check( pre_state_root, encoded_proof, - verifying_method, + execution_method, call_data, domain_runtime_code, ) diff --git a/crates/sp-domains-fraud-proof/src/verification.rs b/crates/sp-domains-fraud-proof/src/verification.rs index 1f041b76d9..704e9eef93 100644 --- a/crates/sp-domains-fraud-proof/src/verification.rs +++ b/crates/sp-domains-fraud-proof/src/verification.rs @@ -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, ) diff --git a/domains/client/domain-operator/src/tests.rs b/domains/client/domain-operator/src/tests.rs index 3563689eb0..2a6269be88 100644 --- a/domains/client/domain-operator/src/tests.rs +++ b/domains/client/domain-operator/src/tests.rs @@ -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(""); @@ -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::();