diff --git a/crates/sp-domains-fraud-proof/src/fraud_proof.rs b/crates/sp-domains-fraud-proof/src/fraud_proof.rs index 57ca6b6ada..b10504e448 100644 --- a/crates/sp-domains-fraud-proof/src/fraud_proof.rs +++ b/crates/sp-domains-fraud-proof/src/fraud_proof.rs @@ -497,8 +497,8 @@ pub struct InvalidExtrinsicsRootProof { /// The combined storage proofs used during verification pub invalid_inherent_extrinsic_proofs: InvalidInherentExtrinsicDataProof, - /// Domain runtime code upgraded (or "not upgraded") storage proof - pub domain_runtime_upgraded_proof: DomainRuntimeUpgradedProof, + /// A single domain runtime code upgrade (or "not upgraded") storage proof + pub domain_runtime_single_upgrade_proof: DomainRuntimeSingleUpgradeProof, /// Storage proof for a change to the chains that are allowed to open a channel with each domain pub domain_chain_allowlist_proof: DomainChainsAllowlistUpdateStorageProof, diff --git a/crates/sp-domains-fraud-proof/src/storage_proof.rs b/crates/sp-domains-fraud-proof/src/storage_proof.rs index ff70b23bd0..06d70b3f9b 100644 --- a/crates/sp-domains-fraud-proof/src/storage_proof.rs +++ b/crates/sp-domains-fraud-proof/src/storage_proof.rs @@ -286,13 +286,17 @@ where } } +/// A proof that the domain runtime was upgraded (or not upgraded). #[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)] -pub struct DomainRuntimeUpgradedProof { +pub struct DomainRuntimeSingleUpgradeProof { + /// A list of domain runtime upgrades for a block. pub domain_runtime_upgrades: DomainRuntimeUpgradesProof, + + /// The new domain runtime code, if the domain runtime was upgraded. pub new_domain_runtime_code: Option, } -impl DomainRuntimeUpgradedProof { +impl DomainRuntimeSingleUpgradeProof { /// Generate the `DomainRuntimeUpgradedProof`. /// It is the caller's responsibility to check if the domain runtime is upgraded at /// `block_hash`. If it is, the `maybe_runtime_id` should be `Some`. @@ -324,7 +328,8 @@ impl DomainRuntimeUpgradedProof { } else { None }; - Ok(DomainRuntimeUpgradedProof { + + Ok(DomainRuntimeSingleUpgradeProof { domain_runtime_upgrades, new_domain_runtime_code, }) diff --git a/crates/sp-domains-fraud-proof/src/verification.rs b/crates/sp-domains-fraud-proof/src/verification.rs index d4497adbe2..83af958020 100644 --- a/crates/sp-domains-fraud-proof/src/verification.rs +++ b/crates/sp-domains-fraud-proof/src/verification.rs @@ -66,7 +66,7 @@ where let InvalidExtrinsicsRootProof { valid_bundle_digests, invalid_inherent_extrinsic_proofs, - domain_runtime_upgraded_proof, + domain_runtime_single_upgrade_proof, domain_chain_allowlist_proof, domain_sudo_call_proof, } = fraud_proof; @@ -79,7 +79,7 @@ where )?; let maybe_domain_runtime_upgrade = - domain_runtime_upgraded_proof.verify::(runtime_id, &state_root)?; + domain_runtime_single_upgrade_proof.verify::(runtime_id, &state_root)?; let domain_chain_allowlist = Result, FraudProofError> { - let header = - self.consensus_client - .header(at)? - .ok_or(sp_blockchain::Error::MissingHeader(format!( - "No header found for {at:?}" - )))?; + // Generate the runtime upgrades list proof + let domain_runtime_upgrades = DomainRuntimeUpgradesProof::generate( + self.consensus_client.as_ref(), + at, + (), + &self.storage_key_provider, + )?; + + // Extract the list data to find out if this runtime was upgraded + let storage_key_req = + >::storage_key_request(()); + let storage_key = self + .storage_key_provider + .storage_key(storage_key_req.clone()) + .expect("just generated proof, so key must exist; qed"); + let domain_runtime_upgrade_list = + StorageProofVerifier::>::get_decoded_value::< + >::StorageValue, + >(&at, domain_runtime_upgrades.into(), StorageKey(storage_key)) + .expect("just generated proof, so it must verify; qed"); let runtime_id = self .consensus_client @@ -447,12 +460,7 @@ where "No RuntimeId found for {domain_id:?}" ))))?; - let is_runtime_upgraded = header - .digest() - .logs - .iter() - .filter_map(|log| log.as_domain_runtime_upgrade()) - .any(|upgraded_runtime_id| upgraded_runtime_id == runtime_id); + let is_runtime_upgraded = domain_runtime_upgrade_list.contains(&runtime_id); Ok(is_runtime_upgraded.then_some(runtime_id)) }