@@ -72,10 +72,10 @@ pub mod pallet {
7272 } ;
7373 use frame_system:: pallet_prelude:: * ;
7474 use ismp:: {
75- consensus:: { ConsensusStateId , StateMachineHeight , StateMachineId } ,
75+ consensus:: { ConsensusStateId , StateCommitment , StateMachineHeight , StateMachineId } ,
7676 handlers,
7777 host:: IsmpHost ,
78- messaging:: { ConsensusMessage as IsmpConsensusMessage , Message } ,
78+ messaging:: { ConsensusMessage as IsmpConsensusMessage , Message , StateCommitmentHeight } ,
7979 } ;
8080 use ismp_abi:: ecdsa_beefy:: BeefyConsensusState as SolBeefyConsensusState ;
8181 use primitive_types:: H256 ;
@@ -227,6 +227,8 @@ pub mod pallet {
227227 UnknownProofType ,
228228 /// ABI decoding or conversion failed.
229229 AbiDecodeFailed ,
230+ /// The submitted proof is not in canonical ABI form (e.g. trailing padding).
231+ MalformedProof ,
230232 /// The BEEFY verifier rejected the proof.
231233 VerificationFailed ,
232234 /// Rotation proof did not rotate to `NextAuthoritySetId`.
@@ -300,7 +302,12 @@ pub mod pallet {
300302 let current_set_id = state. current_authorities . id ;
301303 let next_set_id = state. next_authorities . id ;
302304 let latest_beefy_height = state. latest_beefy_height ;
305+ let host = pallet_ismp:: Pallet :: < T > :: default ( ) ;
303306
307+ // Seed an initial commitment for the host state machine at the current block height.
308+ let height = sp_runtime:: SaturatedConversion :: saturated_into :: < u64 > (
309+ frame_system:: Pallet :: < T > :: block_number ( ) ,
310+ ) ;
304311 pallet_ismp:: Pallet :: < T > :: create_consensus_client (
305312 frame_system:: RawOrigin :: Root . into ( ) ,
306313 ismp:: messaging:: CreateConsensusState {
@@ -309,7 +316,20 @@ pub mod pallet {
309316 consensus_state_id : ismp_beefy:: BEEFY_CONSENSUS_ID ,
310317 unbonding_period : T :: UnbondingPeriod :: get ( ) ,
311318 challenge_periods : Default :: default ( ) ,
312- state_machine_commitments : Default :: default ( ) ,
319+ state_machine_commitments : vec ! [ (
320+ StateMachineId {
321+ consensus_state_id: ismp_beefy:: BEEFY_CONSENSUS_ID ,
322+ state_id: host. host_state_machine( ) ,
323+ } ,
324+ StateCommitmentHeight {
325+ height,
326+ commitment: StateCommitment {
327+ timestamp: host. timestamp( ) . as_secs( ) ,
328+ overlay_root: None ,
329+ state_root: H256 :: zero( ) ,
330+ } ,
331+ } ,
332+ ) ] ,
313333 } ,
314334 )
315335 . map_err ( |e| {
@@ -459,6 +479,14 @@ pub mod pallet {
459479 canonical_proof. extend_from_slice ( & canonical_payload) ;
460480 let proof_hash: H256 = sp_io:: hashing:: keccak_256 ( & canonical_proof) . into ( ) ;
461481
482+ // Reject any submission that isn't already in canonical form. If the raw input
483+ // hashes differently from its canonical re-encoding it carries non-canonical
484+ // bytes (trailing padding, alternate encodings), so it is malformed.
485+ let submitted_hash: H256 = sp_io:: hashing:: keccak_256 ( & proof) . into ( ) ;
486+ if submitted_hash != proof_hash {
487+ Err ( Error :: < T > :: MalformedProof ) ?
488+ }
489+
462490 // Read the pre-proof consensus state before `verify_and_apply` mutates it.
463491 // Used to seed `ProofContext` for the first-proof path.
464492 let host = pallet_ismp:: Pallet :: < T > :: default ( ) ;
0 commit comments