Skip to content

Commit 9040bb9

Browse files
committed
Add parent_hash to FraudProof
`parent_hash` will be used to fetch the runtime code for running the execution.
1 parent c697864 commit 9040bb9

File tree

3 files changed

+30
-5
lines changed
  • crates
  • cumulus/client/cirrus-executor/src

3 files changed

+30
-5
lines changed

crates/sp-executor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ pub enum VerificationError {
210210
/// Fraud proof for the state computation.
211211
#[derive(Decode, Encode, TypeInfo, PartialEq, Eq, Clone, RuntimeDebug)]
212212
pub struct FraudProof {
213+
/// Parent hash of the block at which the invalid execution occurred.
214+
///
215+
/// Runtime code for this block's execution is retrieved on top of the parent block.
216+
pub parent_hash: H256,
213217
/// State root before the fraudulent transaction.
214218
pub pre_state_root: H256,
215219
/// State root after the fraudulent transaction.

crates/subspace-fraud-proof/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,17 @@ impl<
207207

208208
fn verify(&self, proof: &FraudProof) -> Result<(), VerificationError> {
209209
let FraudProof {
210+
parent_hash,
210211
pre_state_root,
211212
post_state_root,
212213
proof,
213214
execution_args,
214215
} = proof;
215216

216-
// TODO: we should use parent_hash.
217-
let at = BlockId::Hash(Block::Hash::default());
217+
let at = BlockId::Hash(
218+
Block::Hash::decode(&mut parent_hash.encode().as_slice())
219+
.expect("Block Hash must be H256; qed"),
220+
);
218221

219222
let state = self
220223
.backend

cumulus/client/cirrus-executor/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,13 @@ where
626626
None,
627627
)?;
628628

629-
FraudProof { pre_state_root, post_state_root, proof, execution_args }
629+
FraudProof {
630+
parent_hash: as_h256(&parent_header.hash())?,
631+
pre_state_root,
632+
post_state_root,
633+
proof,
634+
execution_args,
635+
}
630636
} else if local_trace_idx == local_receipt.trace.len() - 1 {
631637
// `finalize_block` execution proof.
632638
let pre_state_root = as_h256(&execution_receipt.trace[local_trace_idx - 1])?;
@@ -659,7 +665,13 @@ where
659665
Some((delta, post_delta_root)),
660666
)?;
661667

662-
FraudProof { pre_state_root, post_state_root, proof, execution_args }
668+
FraudProof {
669+
parent_hash: as_h256(&parent_header.hash())?,
670+
pre_state_root,
671+
post_state_root,
672+
proof,
673+
execution_args,
674+
}
663675
} else {
664676
// Regular extrinsic execution proof.
665677
let pre_state_root = as_h256(&execution_receipt.trace[local_trace_idx - 1])?;
@@ -672,7 +684,13 @@ where
672684
)?;
673685

674686
// TODO: proof should be a CompactProof.
675-
FraudProof { pre_state_root, post_state_root, proof, execution_args }
687+
FraudProof {
688+
parent_hash: as_h256(&parent_header.hash())?,
689+
pre_state_root,
690+
post_state_root,
691+
proof,
692+
execution_args,
693+
}
676694
};
677695

678696
self.submit_fraud_proof(fraud_proof);

0 commit comments

Comments
 (0)