Skip to content
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
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/kilt-dip-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ version.workspace = true
# External dependencies
hash-db.workspace = true
log.workspace = true
cfg-if.workspace = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can also remove it from the root cargo toml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's still used in the pallet-dip-consumer crate:

// TODO: Maybe find a nicer way to exclude the call dispatched from the
// benchmarks while making sure the call is actually dispatched and passes any
// filters the consumer proof verifier has set.
cfg_if::cfg_if! {
    if #[cfg(not(feature = "runtime-benchmark"))] {
        call.dispatch(did_origin.into())
    } else {
        ().into()
    }
}


# Internal dependencies
did.workspace = true
Expand Down Expand Up @@ -78,5 +77,5 @@ std = [
runtime-benchmarks = [
"kilt-support/runtime-benchmarks",
"pallet-dip-consumer/runtime-benchmarks",
"pallet-dip-provider/runtime-benchmarks",
"pallet-dip-provider/runtime-benchmarks"
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use did::{
did_details::{DidPublicKey, DidPublicKeyDetails},
DidSignature,
};
use frame_support::ensure;
use sp_core::ConstU32;
use sp_runtime::{traits::SaturatedConversion, BoundedVec};
use sp_std::vec::Vec;
Expand All @@ -29,7 +30,6 @@ use crate::{
input_common::TimeBoundDidSignature,
output_common::{DidKeyRelationship, DipOriginInfo, RevealedDidKey, RevealedDidMerkleProofLeaf},
},
traits::BenchmarkDefault,
Error,
};

Expand Down Expand Up @@ -106,13 +106,7 @@ impl<
>,
Error,
> {
cfg_if::cfg_if! {
if #[cfg(feature = "runtime-benchmarks")] {
let _ = self.signature.valid_until >= *block_number;
} else {
frame_support::ensure!(self.signature.valid_until >= *block_number, Error::InvalidSignatureTime);
}
}
ensure!(self.signature.valid_until >= *block_number, Error::InvalidSignatureTime);
Ok(DipRevealedDetailsAndVerifiedDidSignatureFreshness {
revealed_leaves: self.revealed_leaves,
signature: self.signature.signature,
Expand Down Expand Up @@ -166,9 +160,7 @@ impl<
KiltWeb3Name,
KiltLinkableAccountId,
MAX_REVEALED_LEAVES_COUNT,
> where
KiltDidKeyId: BenchmarkDefault,
KiltBlockNumber: BenchmarkDefault,
>
{
/// Iterates over the revealed DID leaves to find the ones that generated a
/// valid signature for the provided payload.
Expand Down Expand Up @@ -214,15 +206,7 @@ impl<
.map(|(index, _)| u32::saturated_from(index))
.collect();

if signing_leaves_indices.is_empty() {
cfg_if::cfg_if! {
if #[cfg(feature = "runtime-benchmarks")] {
return Ok(DipOriginInfo::default());
} else {
return Err(Error::InvalidDidKeyRevealed);
}
}
}
ensure!(!signing_leaves_indices.is_empty(), Error::InvalidDidKeyRevealed);

let signing_leaves_indices_vector = signing_leaves_indices.try_into().map_err(|_| {
log::error!("Should never fail to convert vector of signing leaf indices into BoundedVec.");
Expand Down
71 changes: 17 additions & 54 deletions crates/kilt-dip-primitives/src/merkle_proofs/v0/input_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::vec::Vec;

use crate::{merkle_proofs::v0::output_common::RevealedDidMerkleProofLeaf, utils::BoundedBlindedValue};
use crate::merkle_proofs::v0::output_common::RevealedDidMerkleProofLeaf;

/// The state proof for a parachain head.
///
Expand All @@ -31,31 +31,26 @@ use crate::{merkle_proofs::v0::output_common::RevealedDidMerkleProofLeaf, utils:
#[cfg_attr(test, derive(Default))]
pub struct ProviderHeadStateProof<RelayBlockNumber> {
pub(crate) relay_block_number: RelayBlockNumber,
pub(crate) proof: BoundedBlindedValue<u8>,
pub(crate) proof: Vec<Vec<u8>>,
}

#[cfg(feature = "runtime-benchmarks")]
impl<RelayBlockNumber, Context> kilt_support::traits::GetWorstCase<Context> for ProviderHeadStateProof<RelayBlockNumber>
where
RelayBlockNumber: Default,
{
fn worst_case(context: Context) -> Self {
impl<RelayBlockNumber> ProviderHeadStateProof<RelayBlockNumber> {
pub fn new(relay_block_number: RelayBlockNumber, proof: Vec<Vec<u8>>) -> Self {
Self {
relay_block_number: RelayBlockNumber::default(),
proof: BoundedBlindedValue::worst_case(context),
proof,
relay_block_number,
}
}
}

/// The state proof for a DIP commitment.
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(test, derive(Default))]
pub struct DipCommitmentStateProof(pub(crate) BoundedBlindedValue<u8>);
pub struct DipCommitmentStateProof(pub(crate) Vec<Vec<u8>>);

#[cfg(feature = "runtime-benchmarks")]
impl<Context> kilt_support::traits::GetWorstCase<Context> for DipCommitmentStateProof {
fn worst_case(context: Context) -> Self {
Self(BoundedBlindedValue::worst_case(context))
impl DipCommitmentStateProof {
pub fn new(proof: Vec<Vec<u8>>) -> Self {
Self(proof)
}
}

Expand All @@ -76,7 +71,7 @@ pub struct DidMerkleProof<
ProviderWeb3Name,
ProviderLinkableAccountId,
> {
pub(crate) blinded: BoundedBlindedValue<u8>,
pub(crate) blinded: Vec<Vec<u8>>,
pub(crate) revealed: Vec<
RevealedDidMerkleProofLeaf<
ProviderDidKeyId,
Expand All @@ -92,7 +87,7 @@ impl<ProviderDidKeyId, ProviderAccountId, ProviderBlockNumber, ProviderWeb3Name,
DidMerkleProof<ProviderDidKeyId, ProviderAccountId, ProviderBlockNumber, ProviderWeb3Name, ProviderLinkableAccountId>
{
pub fn new(
blinded: BoundedBlindedValue<u8>,
blinded: Vec<Vec<u8>>,
revealed: Vec<
RevealedDidMerkleProofLeaf<
ProviderDidKeyId,
Expand All @@ -105,35 +100,17 @@ impl<ProviderDidKeyId, ProviderAccountId, ProviderBlockNumber, ProviderWeb3Name,
) -> Self {
Self { blinded, revealed }
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<
pub fn revealed(
&self,
) -> &[RevealedDidMerkleProofLeaf<
ProviderDidKeyId,
ProviderAccountId,
ProviderBlockNumber,
ProviderWeb3Name,
ProviderLinkableAccountId,
Context,
> kilt_support::traits::GetWorstCase<Context>
for DidMerkleProof<
ProviderDidKeyId,
ProviderAccountId,
ProviderBlockNumber,
ProviderWeb3Name,
ProviderLinkableAccountId,
> where
ProviderDidKeyId: Default + Clone,
ProviderAccountId: Clone,
ProviderBlockNumber: Default + Clone,
ProviderWeb3Name: Clone,
ProviderLinkableAccountId: Clone,
{
fn worst_case(context: Context) -> Self {
Self {
blinded: BoundedBlindedValue::worst_case(context),
revealed: sp_std::vec![RevealedDidMerkleProofLeaf::default(); 64],
}
>] {
self.revealed.as_ref()
}
}

Expand Down Expand Up @@ -188,17 +165,3 @@ where
}
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<BlockNumber, Context> kilt_support::traits::GetWorstCase<Context> for TimeBoundDidSignature<BlockNumber>
where
DidSignature: kilt_support::traits::GetWorstCase<Context>,
BlockNumber: Default,
{
fn worst_case(context: Context) -> Self {
Self {
signature: DidSignature::worst_case(context),
valid_until: BlockNumber::default(),
}
}
}
Loading