Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
45 changes: 45 additions & 0 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ pub mod pallet {
InvalidOutboundHrmp,
/// The validation code hash of the candidate is not valid.
InvalidValidationCodeHash,
/// The `para_head` hash in the candidate descriptor doesn't match the hash of the actual para head in the
/// commitments.
ParaHeadMismatch,
}

/// The latest bitfield for each validator, referred to by their index in the validator set.
Expand Down Expand Up @@ -465,6 +468,11 @@ impl<T: Config> Pallet<T> {
Error::<T>::InvalidValidationCodeHash,
);

ensure!(
candidate.descriptor().para_head == candidate.candidate.commitments.head_data.hash(),
Error::<T>::ParaHeadMismatch,
);

if let Err(err) = check_cx.check_validation_outputs(
para_id,
&candidate.candidate.commitments.head_data,
Expand Down Expand Up @@ -1169,6 +1177,7 @@ mod tests {
struct TestCandidateBuilder {
para_id: ParaId,
head_data: HeadData,
para_head_hash: Option<Hash>,
pov_hash: Hash,
relay_parent: Hash,
persisted_validation_data_hash: Hash,
Expand All @@ -1186,6 +1195,7 @@ mod tests {
relay_parent: self.relay_parent,
persisted_validation_data_hash: self.persisted_validation_data_hash,
validation_code_hash: self.validation_code.hash(),
para_head: self.para_head_hash.unwrap_or_else(|| self.head_data.hash()),
..Default::default()
},
commitments: CandidateCommitments {
Expand Down Expand Up @@ -2214,6 +2224,41 @@ mod tests {
Err(Error::<Test>::InvalidValidationCodeHash.into()),
);
}

// Para head hash in descriptor doesn't match head data
{
let mut candidate = TestCandidateBuilder {
para_id: chain_a,
relay_parent: System::parent_hash(),
pov_hash: Hash::repeat_byte(1),
persisted_validation_data_hash: make_vdata_hash(chain_a).unwrap(),
hrmp_watermark: RELAY_PARENT_NUM,
para_head_hash: Some(Hash::random()),
..Default::default()
}
.build();

collator_sign_candidate(Sr25519Keyring::One, &mut candidate);

let backed = block_on(back_candidate(
candidate,
&validators,
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
&keystore,
&signing_context,
BackingKind::Threshold,
));

assert_eq!(
ParaInclusion::process_candidates(
Default::default(),
vec![backed],
vec![chain_a_assignment.clone()],
&group_validators,
),
Err(Error::<Test>::ParaHeadMismatch.into()),
);
}
});
}

Expand Down