Skip to content

Commit b51b689

Browse files
authored
Merge pull request #3312 from autonomys/move-extr-proof-data
Move InvalidExtrinsicsRootProof storage so it is easier to combine later
2 parents aaed3ba + 90428cc commit b51b689

File tree

8 files changed

+64
-49
lines changed

8 files changed

+64
-49
lines changed

crates/pallet-domains/src/block_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ pub(crate) fn prune_receipt<T: Config>(
598598
// If the pruned ER is the operator's `latest_submitted_er` for this domain, it means either:
599599
//
600600
// - All the ER the operator submitted for this domain are confirmed and pruned, so the operator
601-
// can't be targetted by fraud proof later unless it submit other new ERs.
601+
// can't be targeted by fraud proof later unless it submit other new ERs.
602602
//
603603
// - All the bad ER the operator submitted for this domain are pruned and the operator is already
604604
// slashed, so wwe don't need `LatestSubmittedER` to determine if the operator is pending slash.

crates/pallet-domains/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn test_basic_fraud_proof_processing() {
777777

778778
for block_number in bad_receipt_at..=head_domain_number {
779779
if block_number == bad_receipt_at {
780-
// The targetted ER should be removed from the block tree
780+
// The targeted ER should be removed from the block tree
781781
assert!(BlockTree::<Test>::get(domain_id, block_number).is_none());
782782
} else {
783783
// All the bad ER's descendants should be marked as pending to prune and the submitter

crates/sp-domains-fraud-proof/src/fraud_proof.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ pub struct FraudProof<Number, Hash, DomainHeader: HeaderT, MmrHash> {
320320
pub domain_id: DomainId,
321321
/// Hash of the bad receipt this fraud proof targeted
322322
pub bad_receipt_hash: HeaderHashFor<DomainHeader>,
323-
/// The MMR proof for the consensus state root that used to verify the storage proof
323+
/// The MMR proof for the consensus state root that is used to verify the storage proof
324324
///
325-
/// It is set `None` if the specific fraud proof variant doesn't contains storage proof
325+
/// It is set `None` if the specific fraud proof variant doesn't contain a storage proof
326326
pub maybe_mmr_proof: Option<ConsensusChainMmrLeafProof<Number, Hash, MmrHash>>,
327327
/// The domain runtime code storage proof
328328
///
329-
/// It is set `None` if the specific fraud proof variant doesn't required domain runtime code
329+
/// It is set `None` if the specific fraud proof variant doesn't require domain runtime code
330330
/// or the required domain runtime code is available from the current runtime state.
331331
pub maybe_domain_runtime_code_proof: Option<DomainRuntimeCodeAt<Number, Hash, MmrHash>>,
332332
/// The specific fraud proof variant
@@ -485,18 +485,20 @@ pub struct InvalidStateTransitionProof {
485485
/// Fraud proof for the valid bundles in `ExecutionReceipt::inboxed_bundles`
486486
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
487487
pub struct ValidBundleProof<Number, Hash, DomainHeader: HeaderT> {
488-
/// The targetted bundle with proof
488+
/// The targeted bundle with proof
489489
pub bundle_with_proof: OpaqueBundleWithProof<Number, Hash, DomainHeader, Balance>,
490490
}
491491

492492
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
493493
pub struct InvalidExtrinsicsRootProof {
494494
/// Valid Bundle digests
495495
pub valid_bundle_digests: Vec<ValidBundleDigest>,
496-
/// Block randomness storage proof
497-
pub block_randomness_proof: BlockRandomnessProof,
496+
498497
/// The storage proof used during verification
499-
pub domain_inherent_extrinsic_data_proof: DomainInherentExtrinsicDataProof,
498+
pub invalid_extrinsics_data_proof: InvalidExtrinsicsDataProof,
499+
500+
/// Optional sudo extrinsic call storage proof
501+
pub domain_sudo_call_proof: DomainSudoCallStorageProof,
500502
}
501503

502504
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]

crates/sp-domains-fraud-proof/src/host_functions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ where
262262
domain_inherent_extrinsic_data: DomainInherentExtrinsicData,
263263
) -> Option<DomainInherentExtrinsic> {
264264
let DomainInherentExtrinsicData {
265+
// Used by caller
266+
block_randomness: _,
265267
timestamp,
266268
maybe_domain_runtime_upgrade,
267269
consensus_transaction_byte_fee,

crates/sp-domains-fraud-proof/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity};
5454
use sp_runtime::OpaqueExtrinsic;
5555
use sp_runtime_interface::pass_by;
5656
use sp_runtime_interface::pass_by::PassBy;
57-
use subspace_core_primitives::U256;
57+
use subspace_core_primitives::{Randomness, U256};
5858
use subspace_runtime_primitives::{Balance, Moment};
5959

6060
/// Custom invalid validity code for the extrinsics in pallet-domains.
@@ -108,6 +108,7 @@ pub enum DomainChainAllowlistUpdateExtrinsic {
108108

109109
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
110110
pub struct DomainInherentExtrinsicData {
111+
pub block_randomness: Randomness,
111112
pub timestamp: Moment,
112113
pub maybe_domain_runtime_upgrade: Option<Vec<u8>>,
113114
pub consensus_transaction_byte_fee: Balance,

crates/sp-domains-fraud-proof/src/storage_proof.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,27 @@ impl MaybeDomainRuntimeUpgradedProof {
414414
}
415415

416416
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
417-
pub struct DomainInherentExtrinsicDataProof {
417+
pub struct InvalidExtrinsicsDataProof {
418+
/// Block randomness storage proof
419+
pub block_randomness_proof: BlockRandomnessProof,
420+
421+
/// Block timestamp storage proof
418422
pub timestamp_proof: TimestampStorageProof,
423+
424+
/// Optional domain runtime code upgrade storage proof
419425
pub maybe_domain_runtime_upgrade_proof: MaybeDomainRuntimeUpgradedProof,
426+
427+
/// Boolean indicating if dynamic cost of storage was used (but as a storage proof)
420428
pub dynamic_cost_of_storage_proof: DynamicCostOfStorageProof,
429+
430+
/// Transaction fee storage proof
421431
pub consensus_chain_byte_fee_proof: ConsensusTransactionByteFeeProof,
432+
433+
/// Change in the allowed chains storage proof
422434
pub domain_chain_allowlist_proof: DomainChainsAllowlistUpdateStorageProof,
423-
pub domain_sudo_call_proof: DomainSudoCallStorageProof,
424435
}
425436

426-
impl DomainInherentExtrinsicDataProof {
437+
impl InvalidExtrinsicsDataProof {
427438
#[cfg(feature = "std")]
428439
#[allow(clippy::let_and_return)]
429440
pub fn generate<
@@ -437,6 +448,8 @@ impl DomainInherentExtrinsicDataProof {
437448
block_hash: Block::Hash,
438449
maybe_runtime_id: Option<RuntimeId>,
439450
) -> Result<Self, GenerationError> {
451+
let block_randomness_proof =
452+
BlockRandomnessProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
440453
let timestamp_proof =
441454
TimestampStorageProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
442455
let maybe_domain_runtime_upgrade_proof = MaybeDomainRuntimeUpgradedProof::generate(
@@ -464,20 +477,13 @@ impl DomainInherentExtrinsicDataProof {
464477
storage_key_provider,
465478
)?;
466479

467-
let domain_sudo_call_proof = DomainSudoCallStorageProof::generate(
468-
proof_provider,
469-
block_hash,
470-
domain_id,
471-
storage_key_provider,
472-
)?;
473-
474480
Ok(Self {
481+
block_randomness_proof,
475482
timestamp_proof,
476483
maybe_domain_runtime_upgrade_proof,
477484
dynamic_cost_of_storage_proof,
478485
consensus_chain_byte_fee_proof,
479486
domain_chain_allowlist_proof,
480-
domain_sudo_call_proof,
481487
})
482488
}
483489

@@ -487,6 +493,12 @@ impl DomainInherentExtrinsicDataProof {
487493
runtime_id: RuntimeId,
488494
state_root: &Block::Hash,
489495
) -> Result<DomainInherentExtrinsicData, VerificationError> {
496+
let block_randomness = <BlockRandomnessProof as BasicStorageProof<Block>>::verify::<SKP>(
497+
self.block_randomness_proof.clone(),
498+
(),
499+
state_root,
500+
)?;
501+
490502
let timestamp = <TimestampStorageProof as BasicStorageProof<Block>>::verify::<SKP>(
491503
self.timestamp_proof.clone(),
492504
(),
@@ -523,18 +535,14 @@ impl DomainInherentExtrinsicDataProof {
523535
state_root,
524536
)?;
525537

526-
let domain_sudo_call = <DomainSudoCallStorageProof as BasicStorageProof<Block>>::verify::<
527-
SKP,
528-
>(
529-
self.domain_sudo_call_proof.clone(), domain_id, state_root
530-
)?;
531-
532538
Ok(DomainInherentExtrinsicData {
539+
block_randomness,
533540
timestamp,
534541
maybe_domain_runtime_upgrade,
535542
consensus_transaction_byte_fee,
536543
domain_chain_allowlist,
537-
maybe_sudo_runtime_call: domain_sudo_call.maybe_call,
544+
// Populated by caller
545+
maybe_sudo_runtime_call: None,
538546
})
539547
}
540548
}

crates/sp-domains-fraud-proof/src/verification.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,24 @@ where
6565
{
6666
let InvalidExtrinsicsRootProof {
6767
valid_bundle_digests,
68-
block_randomness_proof,
69-
domain_inherent_extrinsic_data_proof,
70-
..
68+
invalid_extrinsics_data_proof,
69+
domain_sudo_call_proof,
7170
} = fraud_proof;
7271

73-
let domain_inherent_extrinsic_data = domain_inherent_extrinsic_data_proof
74-
.verify::<CBlock, SKP>(domain_id, runtime_id, &state_root)?;
72+
let mut domain_inherent_extrinsic_data =
73+
invalid_extrinsics_data_proof.verify::<CBlock, SKP>(domain_id, runtime_id, &state_root)?;
7574

76-
let block_randomness = <BlockRandomnessProof as BasicStorageProof<CBlock>>::verify::<SKP>(
77-
block_randomness_proof.clone(),
78-
(),
75+
let domain_sudo_call = <DomainSudoCallStorageProof as BasicStorageProof<CBlock>>::verify::<SKP>(
76+
domain_sudo_call_proof.clone(),
77+
domain_id,
7978
&state_root,
8079
)?;
80+
domain_inherent_extrinsic_data.maybe_sudo_runtime_call = domain_sudo_call.maybe_call;
81+
82+
let shuffling_seed = H256::from_slice(
83+
extrinsics_shuffling_seed::<Hashing>(domain_inherent_extrinsic_data.block_randomness)
84+
.as_ref(),
85+
);
8186

8287
let DomainInherentExtrinsic {
8388
domain_timestamp_extrinsic,
@@ -110,9 +115,6 @@ where
110115
bundle_extrinsics_digests.extend(bundle_digest.bundle_digest.clone());
111116
}
112117

113-
let shuffling_seed =
114-
H256::from_slice(extrinsics_shuffling_seed::<Hashing>(block_randomness).as_ref());
115-
116118
let mut ordered_extrinsics = deduplicate_and_shuffle_extrinsics(
117119
bundle_extrinsics_digests,
118120
Randomness::from(shuffling_seed.to_fixed_bytes()),

domains/client/domain-operator/src/fraud_proof.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,33 +379,33 @@ where
379379
let maybe_domain_runtime_code_proof =
380380
self.maybe_generate_domain_runtime_code_proof_for_receipt(domain_id, local_receipt)?;
381381

382-
let block_randomness_proof = BlockRandomnessProof::generate(
383-
self.consensus_client.as_ref(),
384-
consensus_block_hash,
385-
(),
386-
&self.storage_key_provider,
387-
)?;
388-
389382
let maybe_runtime_id =
390383
self.is_domain_runtime_updraded_at(domain_id, consensus_block_hash)?;
391384

392-
let domain_inherent_extrinsic_data_proof = DomainInherentExtrinsicDataProof::generate(
385+
let invalid_extrinsics_data_proof = InvalidExtrinsicsDataProof::generate(
393386
&self.storage_key_provider,
394387
self.consensus_client.as_ref(),
395388
domain_id,
396389
consensus_block_hash,
397390
maybe_runtime_id,
398391
)?;
399392

393+
let domain_sudo_call_proof = DomainSudoCallStorageProof::generate(
394+
self.consensus_client.as_ref(),
395+
consensus_block_hash,
396+
domain_id,
397+
&self.storage_key_provider,
398+
)?;
399+
400400
let invalid_domain_extrinsics_root_proof = FraudProof {
401401
domain_id,
402402
bad_receipt_hash,
403403
maybe_mmr_proof: Some(mmr_proof),
404404
maybe_domain_runtime_code_proof,
405405
proof: FraudProofVariant::InvalidExtrinsicsRoot(InvalidExtrinsicsRootProof {
406406
valid_bundle_digests,
407-
block_randomness_proof,
408-
domain_inherent_extrinsic_data_proof,
407+
invalid_extrinsics_data_proof,
408+
domain_sudo_call_proof,
409409
}),
410410
};
411411

0 commit comments

Comments
 (0)