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

Move InvalidExtrinsicsRootProof storage so it is easier to combine later #3312

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pallet-domains/src/block_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ pub(crate) fn prune_receipt<T: Config>(
// If the pruned ER is the operator's `latest_submitted_er` for this domain, it means either:
//
// - All the ER the operator submitted for this domain are confirmed and pruned, so the operator
// can't be targetted by fraud proof later unless it submit other new ERs.
// can't be targeted by fraud proof later unless it submit other new ERs.
//
// - All the bad ER the operator submitted for this domain are pruned and the operator is already
// slashed, so wwe don't need `LatestSubmittedER` to determine if the operator is pending slash.
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn test_basic_fraud_proof_processing() {

for block_number in bad_receipt_at..=head_domain_number {
if block_number == bad_receipt_at {
// The targetted ER should be removed from the block tree
// The targeted ER should be removed from the block tree
assert!(BlockTree::<Test>::get(domain_id, block_number).is_none());
} else {
// All the bad ER's descendants should be marked as pending to prune and the submitter
Expand Down
16 changes: 9 additions & 7 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ pub struct FraudProof<Number, Hash, DomainHeader: HeaderT, MmrHash> {
pub domain_id: DomainId,
/// Hash of the bad receipt this fraud proof targeted
pub bad_receipt_hash: HeaderHashFor<DomainHeader>,
/// The MMR proof for the consensus state root that used to verify the storage proof
/// The MMR proof for the consensus state root that is used to verify the storage proof
///
/// It is set `None` if the specific fraud proof variant doesn't contains storage proof
/// It is set `None` if the specific fraud proof variant doesn't contain a storage proof
pub maybe_mmr_proof: Option<ConsensusChainMmrLeafProof<Number, Hash, MmrHash>>,
/// The domain runtime code storage proof
///
/// It is set `None` if the specific fraud proof variant doesn't required domain runtime code
/// It is set `None` if the specific fraud proof variant doesn't require domain runtime code
/// or the required domain runtime code is available from the current runtime state.
pub maybe_domain_runtime_code_proof: Option<DomainRuntimeCodeAt<Number, Hash, MmrHash>>,
/// The specific fraud proof variant
Expand Down Expand Up @@ -485,18 +485,20 @@ pub struct InvalidStateTransitionProof {
/// Fraud proof for the valid bundles in `ExecutionReceipt::inboxed_bundles`
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct ValidBundleProof<Number, Hash, DomainHeader: HeaderT> {
/// The targetted bundle with proof
/// The targeted bundle with proof
pub bundle_with_proof: OpaqueBundleWithProof<Number, Hash, DomainHeader, Balance>,
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct InvalidExtrinsicsRootProof {
/// Valid Bundle digests
pub valid_bundle_digests: Vec<ValidBundleDigest>,
/// Block randomness storage proof
pub block_randomness_proof: BlockRandomnessProof,

/// The storage proof used during verification
pub domain_inherent_extrinsic_data_proof: DomainInherentExtrinsicDataProof,
pub invalid_extrinsics_data_proof: InvalidExtrinsicsDataProof,

/// Optional sudo extrinsic call storage proof
pub domain_sudo_call_proof: DomainSudoCallStorageProof,
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
Expand Down
2 changes: 2 additions & 0 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ where
domain_inherent_extrinsic_data: DomainInherentExtrinsicData,
) -> Option<DomainInherentExtrinsic> {
let DomainInherentExtrinsicData {
// Used by caller
block_randomness: _,
Copy link
Member Author

Choose a reason for hiding this comment

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

This PR contains a host function change, which we are planning to revert in #3314

timestamp,
maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee,
Expand Down
3 changes: 2 additions & 1 deletion crates/sp-domains-fraud-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity};
use sp_runtime::OpaqueExtrinsic;
use sp_runtime_interface::pass_by;
use sp_runtime_interface::pass_by::PassBy;
use subspace_core_primitives::U256;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::{Balance, Moment};

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

#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct DomainInherentExtrinsicData {
pub block_randomness: Randomness,
pub timestamp: Moment,
pub maybe_domain_runtime_upgrade: Option<Vec<u8>>,
pub consensus_transaction_byte_fee: Balance,
Expand Down
44 changes: 26 additions & 18 deletions crates/sp-domains-fraud-proof/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,27 @@ impl MaybeDomainRuntimeUpgradedProof {
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct DomainInherentExtrinsicDataProof {
pub struct InvalidExtrinsicsDataProof {
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocker but it may be worth having Inherent in the name, to distinguish it from the invalid extrinsic from the invalid bundle fraud proof.

/// Block randomness storage proof
pub block_randomness_proof: BlockRandomnessProof,

/// Block timestamp storage proof
pub timestamp_proof: TimestampStorageProof,

/// Optional domain runtime code upgrade storage proof
pub maybe_domain_runtime_upgrade_proof: MaybeDomainRuntimeUpgradedProof,

/// Boolean indicating if dynamic cost of storage was used (but as a storage proof)
pub dynamic_cost_of_storage_proof: DynamicCostOfStorageProof,

/// Transaction fee storage proof
pub consensus_chain_byte_fee_proof: ConsensusTransactionByteFeeProof,

/// Change in the allowed chains storage proof
pub domain_chain_allowlist_proof: DomainChainsAllowlistUpdateStorageProof,
pub domain_sudo_call_proof: DomainSudoCallStorageProof,
}

impl DomainInherentExtrinsicDataProof {
impl InvalidExtrinsicsDataProof {
#[cfg(feature = "std")]
#[allow(clippy::let_and_return)]
pub fn generate<
Expand All @@ -437,6 +448,8 @@ impl DomainInherentExtrinsicDataProof {
block_hash: Block::Hash,
maybe_runtime_id: Option<RuntimeId>,
) -> Result<Self, GenerationError> {
let block_randomness_proof =
BlockRandomnessProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
let timestamp_proof =
TimestampStorageProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
let maybe_domain_runtime_upgrade_proof = MaybeDomainRuntimeUpgradedProof::generate(
Expand Down Expand Up @@ -464,20 +477,13 @@ impl DomainInherentExtrinsicDataProof {
storage_key_provider,
)?;

let domain_sudo_call_proof = DomainSudoCallStorageProof::generate(
proof_provider,
block_hash,
domain_id,
storage_key_provider,
)?;

Ok(Self {
block_randomness_proof,
timestamp_proof,
maybe_domain_runtime_upgrade_proof,
dynamic_cost_of_storage_proof,
consensus_chain_byte_fee_proof,
domain_chain_allowlist_proof,
domain_sudo_call_proof,
})
}

Expand All @@ -487,6 +493,12 @@ impl DomainInherentExtrinsicDataProof {
runtime_id: RuntimeId,
state_root: &Block::Hash,
) -> Result<DomainInherentExtrinsicData, VerificationError> {
let block_randomness = <BlockRandomnessProof as BasicStorageProof<Block>>::verify::<SKP>(
self.block_randomness_proof.clone(),
(),
state_root,
)?;

let timestamp = <TimestampStorageProof as BasicStorageProof<Block>>::verify::<SKP>(
self.timestamp_proof.clone(),
(),
Expand Down Expand Up @@ -523,18 +535,14 @@ impl DomainInherentExtrinsicDataProof {
state_root,
)?;

let domain_sudo_call = <DomainSudoCallStorageProof as BasicStorageProof<Block>>::verify::<
SKP,
>(
self.domain_sudo_call_proof.clone(), domain_id, state_root
)?;

Ok(DomainInherentExtrinsicData {
block_randomness,
timestamp,
maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee,
domain_chain_allowlist,
maybe_sudo_runtime_call: domain_sudo_call.maybe_call,
// Populated by caller
maybe_sudo_runtime_call: None,
})
}
}
Expand Down
24 changes: 13 additions & 11 deletions crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,24 @@ where
{
let InvalidExtrinsicsRootProof {
valid_bundle_digests,
block_randomness_proof,
domain_inherent_extrinsic_data_proof,
..
invalid_extrinsics_data_proof,
domain_sudo_call_proof,
} = fraud_proof;

let domain_inherent_extrinsic_data = domain_inherent_extrinsic_data_proof
.verify::<CBlock, SKP>(domain_id, runtime_id, &state_root)?;
let mut domain_inherent_extrinsic_data =
invalid_extrinsics_data_proof.verify::<CBlock, SKP>(domain_id, runtime_id, &state_root)?;

let block_randomness = <BlockRandomnessProof as BasicStorageProof<CBlock>>::verify::<SKP>(
block_randomness_proof.clone(),
(),
let domain_sudo_call = <DomainSudoCallStorageProof as BasicStorageProof<CBlock>>::verify::<SKP>(
domain_sudo_call_proof.clone(),
domain_id,
&state_root,
)?;
domain_inherent_extrinsic_data.maybe_sudo_runtime_call = domain_sudo_call.maybe_call;

let shuffling_seed = H256::from_slice(
extrinsics_shuffling_seed::<Hashing>(domain_inherent_extrinsic_data.block_randomness)
.as_ref(),
);

let DomainInherentExtrinsic {
domain_timestamp_extrinsic,
Expand Down Expand Up @@ -110,9 +115,6 @@ where
bundle_extrinsics_digests.extend(bundle_digest.bundle_digest.clone());
}

let shuffling_seed =
H256::from_slice(extrinsics_shuffling_seed::<Hashing>(block_randomness).as_ref());

let mut ordered_extrinsics = deduplicate_and_shuffle_extrinsics(
bundle_extrinsics_digests,
Randomness::from(shuffling_seed.to_fixed_bytes()),
Expand Down
20 changes: 10 additions & 10 deletions domains/client/domain-operator/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,33 +379,33 @@ where
let maybe_domain_runtime_code_proof =
self.maybe_generate_domain_runtime_code_proof_for_receipt(domain_id, local_receipt)?;

let block_randomness_proof = BlockRandomnessProof::generate(
self.consensus_client.as_ref(),
consensus_block_hash,
(),
&self.storage_key_provider,
)?;

let maybe_runtime_id =
self.is_domain_runtime_updraded_at(domain_id, consensus_block_hash)?;

let domain_inherent_extrinsic_data_proof = DomainInherentExtrinsicDataProof::generate(
let invalid_extrinsics_data_proof = InvalidExtrinsicsDataProof::generate(
&self.storage_key_provider,
self.consensus_client.as_ref(),
domain_id,
consensus_block_hash,
maybe_runtime_id,
)?;

let domain_sudo_call_proof = DomainSudoCallStorageProof::generate(
self.consensus_client.as_ref(),
consensus_block_hash,
domain_id,
&self.storage_key_provider,
)?;

let invalid_domain_extrinsics_root_proof = FraudProof {
domain_id,
bad_receipt_hash,
maybe_mmr_proof: Some(mmr_proof),
maybe_domain_runtime_code_proof,
proof: FraudProofVariant::InvalidExtrinsicsRoot(InvalidExtrinsicsRootProof {
valid_bundle_digests,
block_randomness_proof,
domain_inherent_extrinsic_data_proof,
invalid_extrinsics_data_proof,
domain_sudo_call_proof,
}),
};

Expand Down
Loading