diff --git a/contracts/src/Verification.sol b/contracts/src/Verification.sol index 7a1bfe64eb..391601b91d 100644 --- a/contracts/src/Verification.sol +++ b/contracts/src/Verification.sol @@ -76,6 +76,9 @@ library Verification { uint256 public constant DIGEST_ITEM_PRERUNTIME = 6; uint256 public constant DIGEST_ITEM_RUNTIME_ENVIRONMENT_UPDATED = 8; + /// @dev Enum variant ID for CustomDigestItem::Snowbridge + bytes1 public constant DIGEST_ITEM_OTHER_SNOWBRIDGE = 0x00; + /// @dev Verify the message commitment by applying several proofs /// /// 1. First check that the commitment is included in the digest items of the parachain header @@ -132,8 +135,11 @@ library Verification { returns (bool) { for (uint256 i = 0; i < header.digestItems.length; i++) { - DigestItem memory item = header.digestItems[i]; - if (item.kind == DIGEST_ITEM_OTHER && item.data.length == 32 && commitment == bytes32(item.data)) { + if ( + header.digestItems[i].kind == DIGEST_ITEM_OTHER && header.digestItems[i].data.length == 33 + && header.digestItems[i].data[0] == DIGEST_ITEM_OTHER_SNOWBRIDGE + && commitment == bytes32(header.digestItems[i].data[1:]) + ) { return true; } } diff --git a/contracts/test/Verification.t.sol b/contracts/test/Verification.t.sol index 7e6ce46478..53bb77a3b1 100644 --- a/contracts/test/Verification.t.sol +++ b/contracts/test/Verification.t.sol @@ -88,7 +88,7 @@ contract VerificationTest is Test { digestItems[2] = Verification.DigestItem({ kind: 0, consensusEngineID: 0x00000000, - data: hex"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" + data: hex"00b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" }); digestItems[3] = Verification.DigestItem({ kind: 5, diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 7e79563be6..824db20b41 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -1622,6 +1622,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "snowbridge-core", + "sp-core", "sp-runtime", "sp-std 8.0.0", "staging-xcm", diff --git a/parachain/pallets/outbound-queue/src/lib.rs b/parachain/pallets/outbound-queue/src/lib.rs index 6c461510b3..d4ffe24a5f 100644 --- a/parachain/pallets/outbound-queue/src/lib.rs +++ b/parachain/pallets/outbound-queue/src/lib.rs @@ -90,7 +90,7 @@ mod mock; #[cfg(test)] mod test; -use bridge_hub_common::AggregateMessageOrigin; +use bridge_hub_common::{AggregateMessageOrigin, CustomDigestItem}; use codec::Decode; use frame_support::{ storage::StorageStreamIter, @@ -104,7 +104,10 @@ use snowbridge_core::{ use snowbridge_outbound_queue_merkle_tree::merkle_root; pub use snowbridge_outbound_queue_merkle_tree::MerkleProof; use sp_core::{H256, U256}; -use sp_runtime::traits::{CheckedDiv, Hash}; +use sp_runtime::{ + traits::{CheckedDiv, Hash}, + DigestItem, +}; use sp_std::prelude::*; pub use types::{CommittedMessage, FeeConfigRecord, ProcessMessageOriginOf}; pub use weights::WeightInfo; @@ -277,10 +280,10 @@ pub mod pallet { // Create merkle root of messages let root = merkle_root::<::Hashing, _>(MessageLeaves::::stream_iter()); + let digest_item: DigestItem = CustomDigestItem::Snowbridge(root).into(); + // Insert merkle root into the header digest - >::deposit_log(sp_runtime::DigestItem::Other( - root.to_fixed_bytes().into(), - )); + >::deposit_log(digest_item); Self::deposit_event(Event::MessagesCommitted { root, count }); } diff --git a/parachain/pallets/outbound-queue/src/test.rs b/parachain/pallets/outbound-queue/src/test.rs index 7db5fbec2c..675fa12911 100644 --- a/parachain/pallets/outbound-queue/src/test.rs +++ b/parachain/pallets/outbound-queue/src/test.rs @@ -237,3 +237,15 @@ fn convert_local_currency() { assert_eq!(fee, fee2); }); } + +#[test] +fn encode_digest_item() { + new_tester().execute_with(|| { + let digest_item: DigestItem = CustomDigestItem::Snowbridge(H256::default()).into(); + let enum_prefix = match digest_item { + DigestItem::Other(data) => data[0], + _ => u8::MAX, + }; + assert_eq!(enum_prefix, 0); + }); +} diff --git a/polkadot-sdk b/polkadot-sdk index 85470f8b06..46056e6275 160000 --- a/polkadot-sdk +++ b/polkadot-sdk @@ -1 +1 @@ -Subproject commit 85470f8b062e356a80d2b47c4c3cd68281811caf +Subproject commit 46056e6275dba70f09a359516109de26951c14bc diff --git a/relayer/relays/parachain/digest_item.go b/relayer/relays/parachain/digest_item.go index 425493d206..1304d0027f 100644 --- a/relayer/relays/parachain/digest_item.go +++ b/relayer/relays/parachain/digest_item.go @@ -7,12 +7,16 @@ import ( func ExtractCommitmentFromDigest(digest types.Digest) (*types.H256, error) { for _, digestItem := range digest { if digestItem.IsOther { - var commitment types.H256 - err := types.DecodeFromBytes(digestItem.AsOther, &commitment) - if err != nil { - return nil, err + digestItemRawBytes := digestItem.AsOther + // Prefix 0 reserved for snowbridge + if digestItemRawBytes[0] == 0 { + var commitment types.H256 + err := types.DecodeFromBytes(digestItemRawBytes[1:], &commitment) + if err != nil { + return nil, err + } + return &commitment, nil } - return &commitment, nil } } return nil, nil