Skip to content

Conversation

@ntn-x2
Copy link
Contributor

@ntn-x2 ntn-x2 commented Mar 4, 2024

Fixes https://github.com/KILTprotocol/ticket/issues/3104, based on top of #611.

It fixes the logic for the dip-consumer pallet, by delegating the generation of a proof worst case to the proof verifier, which must make sure the proof is indeed the one that requires the most weight to verify, and that it verifies successfully. This also means that each consumer runtime is responsible to implement this method, as there cannot be a "universal" worst proof, as that depends on the use case. The pallet benchmarking logic is now generic enough to make this possible and flexible ✨✨✨

@ntn-x2 ntn-x2 self-assigned this Mar 4, 2024
@ntn-x2 ntn-x2 changed the base branch from develop to aa/dip-consumer-tests March 4, 2024 16:06
proof: Self::Proof,
) -> Result<Self::VerificationResult, Self::Error> {
<ProviderTemplateProofVerifier as IdentityProofVerifier<Runtime>>::verify_proof_for_call_against_details(
call,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reviewers can skip this altogether, as it's been generated in a test setup and copy-pasted here. The unit test below is more meaningful to review.

T::AccountId: Instanciate,
T::Identifier: Instanciate,
<<T as Config>::IdentityProvider as IdentityProvider<T>>::Success: GetWorstCase<IdentityContext<T::Identifier, T::AccountId>>
<<T as Config>::IdentityProvider as IdentityProvider<T>>::Success: GetWorstCase<IdentityContext<T::Identifier, T::AccountId>, Output = <<T as Config>::IdentityProvider as IdentityProvider<T>>::Success>
Copy link
Contributor Author

@ntn-x2 ntn-x2 Mar 6, 2024

Choose a reason for hiding this comment

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

This is a quick fix to ensure nothing breaks with the new definition of the GetWorstCase trait. The logic can be refined in future PRs.

@ntn-x2 ntn-x2 marked this pull request as ready for review March 6, 2024 09:18
@ntn-x2 ntn-x2 requested a review from Ad96el March 6, 2024 09:18
@ntn-x2 ntn-x2 force-pushed the aa/dip-improved-benchmarks branch from f49354e to bfc7ae5 Compare March 7, 2024 13:38
Copy link
Contributor

@Ad96el Ad96el left a comment

Choose a reason for hiding this comment

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

LGTM. Elegant solution. 3 Minor comments.

# 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()
    }
}

const MAX_DID_MERKLE_PROOF_LEAVE_COUNT: u32 = 64,
const MAX_DID_MERKLE_PROOF_LEAVE_SIZE: u32 = 1024,
const MAX_DID_MERKLE_LEAVES_REVEALED: u32 = 64,
const MAX_PROVIDER_HEAD_PROOF_LEAVE_COUNT: u32 = DEFAULT_MAX_PROVIDER_HEAD_PROOF_LEAVE_COUNT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intended to increase the MAX_PROVIDER_HEAD_PROOF_LEAVE_COUNT from 64 to 128? Same for the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I noticed every proof I generated was larger than 64, so I bumped it up to the next power of 2. These are anyway default values, can be overridden by specific consumers.

ConsumerBlockNumber,
>,
) -> Self {
Self::V0(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

What if a new version is introduced? Is there a way to distinguish them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a new version is introduced, it will be because of a breaking change, so they will be different from each other. Otherwise if they cannot be distinguished, why would they be different in their versions?

Changing the storage hasher before we deploy on production, otherwise we
would then need a migration strategy. I think
we can disregard any migrations on our testnets, as the effort is not
justified.

I also lowered the limits of the DIP provider template, which were
higher than Peregrine, so that it is faster to generate the benchmark
worst case.

Related to #601, based on
top of #612.
@ntn-x2 ntn-x2 merged commit 4adad21 into aa/dip-consumer-tests Mar 28, 2024
@ntn-x2 ntn-x2 deleted the aa/dip-improved-benchmarks branch March 28, 2024 07:32
ntn-x2 added a commit that referenced this pull request Mar 28, 2024
Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Adds unit tests for the verifier components (components tested are shown
in the checklist below).
It also splits up the proof verification logic into multiple files,
split by when those checks are performed. Check the
`crates/kilt-dip-primitives/src/merkle/v0/` folder for more details. It
addresses an open comment in the DIP refactoring PR:
#602 (comment).

## Elements to add tests for

- [x] `pallet-dip-consumer`
- [x] `pallet-relay-store`
- [x] `ProofVerifier`
- [x] Merge #612
- [x] Merge #613
Ad96el pushed a commit that referenced this pull request Apr 2, 2024
Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Adds unit tests for the verifier components (components tested are shown
in the checklist below).
It also splits up the proof verification logic into multiple files,
split by when those checks are performed. Check the
`crates/kilt-dip-primitives/src/merkle/v0/` folder for more details. It
addresses an open comment in the DIP refactoring PR:
#602 (comment).

## Elements to add tests for

- [x] `pallet-dip-consumer`
- [x] `pallet-relay-store`
- [x] `ProofVerifier`
- [x] Merge #612
- [x] Merge #613
ntn-x2 added a commit that referenced this pull request Apr 4, 2024
Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Adds unit tests for the verifier components (components tested are shown
in the checklist below).
It also splits up the proof verification logic into multiple files,
split by when those checks are performed. Check the
`crates/kilt-dip-primitives/src/merkle/v0/` folder for more details. It
addresses an open comment in the DIP refactoring PR:
#602 (comment).

## Elements to add tests for

- [x] `pallet-dip-consumer`
- [x] `pallet-relay-store`
- [x] `ProofVerifier`
- [x] Merge #612
- [x] Merge #613
hacker-nova7431 added a commit to hacker-nova7431/kilt-node that referenced this pull request Sep 29, 2025
Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Adds unit tests for the verifier components (components tested are shown
in the checklist below).
It also splits up the proof verification logic into multiple files,
split by when those checks are performed. Check the
`crates/kilt-dip-primitives/src/merkle/v0/` folder for more details. It
addresses an open comment in the DIP refactoring PR:
KILTprotocol/kilt-node#602 (comment).

## Elements to add tests for

- [x] `pallet-dip-consumer`
- [x] `pallet-relay-store`
- [x] `ProofVerifier`
- [x] Merge KILTprotocol/kilt-node#612
- [x] Merge KILTprotocol/kilt-node#613
infra-riderju74 added a commit to infra-riderju74/kilt-node that referenced this pull request Oct 27, 2025
Partially fixes https://github.com/KILTprotocol/ticket/issues/2562.

Adds unit tests for the verifier components (components tested are shown
in the checklist below).
It also splits up the proof verification logic into multiple files,
split by when those checks are performed. Check the
`crates/kilt-dip-primitives/src/merkle/v0/` folder for more details. It
addresses an open comment in the DIP refactoring PR:
KILTprotocol/kilt-node#602 (comment).

## Elements to add tests for

- [x] `pallet-dip-consumer`
- [x] `pallet-relay-store`
- [x] `ProofVerifier`
- [x] Merge KILTprotocol/kilt-node#612
- [x] Merge KILTprotocol/kilt-node#613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants