Skip to content

Commit

Permalink
feat: basic DIP structure (#489)
Browse files Browse the repository at this point in the history
Fixes KILTprotocol/ticket#2550.

**This PR will merge the changes into the `aa/dip` branch, which will be
the base branch for all the future DIP improvements until we reach a
version that we can merge into `develop` and deploy on some testnets in
the Peregrine runtime.**

## Base structure for DIP

This PR contains the following components:

* A pallet to send identity information to one or more destinations (DIP
sender)
* A pallet to receive such identity information from a source (DIP
receiver)
* A support crate that contains common (versioned) types, in future also
traits and auxiliary functions, if needed
* A template project consisting of 1. a template runtime for the
dip-sender, with its node counterpart, 2. a template runtime for the
dip-receiver, with its node counterpart, 3. an example XCM integration
test using [XCM emulator](https://github.com/shaunxw/xcm-simulator) (not
simulator) which connects the two template runtimes with a local Rococo
relay chain.

### Design

The current version assumes that anyone on the sender chain can dispatch
identity information on some target chain (with which there exists an
open HRMP channel). Ultimately, all the fees for dispatching the message
and process it on the receiver side will be paid by the extrinsic
submitter on the target chain. Right now, the submitter only pays for
the extrinsic dispatch on the source chain, and the chain itself uses
its own balance (liked to its sovereign account) on the target chain to
pay for the `Transact` execution. The `Transact` operation that
interacts with the `dip-receiver` pallet on the target chain has an
`OriginKind::Native`, so that there is no way for any user on the source
chain to dispatch such messages.

Right now, the basic structure and the templates use defaults for
everything, from proof generation to proof verification. One step at the
time, all these defaults will be replaced with the actual features.
Nevertheless, for two chains that have the same concept of `Identifier`
and `AccountId`, it is already possible to demo the complete e2e flow.
For the sake of our demonstration, the flow would go as follow,
**assuming that both the source and target chains are registered as
parachain on the same relaychain**:

1. The source chain requests to open an HRMP channel with the target
chain
2. The target chain accepts the request and the channel is open
3. The target chain issues some funds (enough to cover the demo use
case) to the sender chain's sovereign account
4. A user on the source chain creates a DID with a single authentication
key
5. The same user (but could be anyone else), calls the extrinsic on the
`dip-sender` pallet to send the merkle root of the DID to the target
chain, paying for the dispatch fee
6. The source chain sends the information to the target chain
7. The user calls the `dispatch_as` extrinsic of the `dip-receiver`
pallet which is deployed on the target chain, providing a merkle proof
of their DID document + details on the source chain. For now this check
always returns true.
8. Inside, the `dispatch_as` has a nested call which is dispatched with
the new `DipOrigin`, which pallets can now use if they expect extrinsics
to be DID-authorized.

## What's coming

I created tickets for each of the next steps, under the DIP milestone.
The tickets will take care of:

* Adding benchmarks and weights
* Introducing proper error handling
* Introducing proper DID signature verificaiton on the target template
chain (right now it's just a default behaviour)
* Introducing proper merkle proof generation (I tested that it works,
but removed those pieces from this PR for the ease of understanding)
* Introducing proper merkle proof verification (same as above)
* Adding an emergency brake in the sender pallet to stop dispatching
messages to a specific destination, e.g., if the sender sovereign
account on the destination chain does not have any more or if the
`Transact` encoding would fail
* Adding support for metadata beyond the simple DID details, e.g., proof
expiration time, etc.
* Replacing user-provided weights and assets with per-chain
configurations stored in the sender pallet
* More comments (I can work on this first if the code as it is it's too
hard to follow)
* Adding support for version negotiation. There is a basic concept of
versioning right now, but it can and should be expanded and improved.
* More unit and integration tests.

Probably more tickets will come out of this work, and will be tracked
separately in the same or in future milestones.

## How to test

A basic integration test of the two template runtimes is present in the
`dip-templates-xcm-tests` crate, inside the
`dip-template/runtimes/xcm-tests`. It can be run as usual with `cargo
test -p dip-templates-xcm-tests`.
  • Loading branch information
ntn-x2 authored Apr 4, 2023
1 parent df9cef8 commit 98de546
Show file tree
Hide file tree
Showing 44 changed files with 5,665 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@
# ignore vscode settings
.vscode

# Custom Polkadot-js apps types
pallets/did/src/custom_types.json

**/__pycache__
304 changes: 304 additions & 0 deletions Cargo.lock

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

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ version = "1.11.0-dev"

[workspace]
members = [
"crates/*",
"dip-template/nodes/*",
"dip-template/runtimes/*",
"nodes/*",
"pallets/*",
"runtime-api/*",
"runtimes/*",
"support",
"crates/*",
]

[profile.release]
Expand Down Expand Up @@ -49,17 +51,24 @@ attestation = {path = "pallets/attestation", default-features = false}
ctype = {path = "pallets/ctype", default-features = false}
delegation = {path = "pallets/delegation", default-features = false}
did = {path = "pallets/did", default-features = false}
pallet-dip-receiver = {path = "pallets/pallet-dip-receiver", default-features = false}
pallet-dip-sender = {path = "pallets/pallet-dip-sender", default-features = false}
pallet-did-lookup = {path = "pallets/pallet-did-lookup", default-features = false}
pallet-inflation = {path = "pallets/pallet-inflation", default-features = false}
pallet-web3-names = {path = "pallets/pallet-web3-names", default-features = false}
parachain-staking = {path = "pallets/parachain-staking", default-features = false}
public-credentials = {path = "pallets/public-credentials", default-features = false}

# Internal support (with default disabled)
dip-support = {path = "crates/dip", default-features = false}
kilt-asset-dids = {path = "crates/assets", default-features = false}
kilt-support = {path = "support", default-features = false}
runtime-common = {path = "runtimes/common", default-features = false}

# Templates
dip-receiver-runtime-template = {path = "dip-template/runtimes/dip-receiver", default-features = false}
dip-sender-runtime-template = {path = "dip-template/runtimes/dip-sender", default-features = false}

# Internal runtime API (with default disabled)
kilt-runtime-api-did = {path = "runtime-api/did", default-features = false}
kilt-runtime-api-public-credentials = {path = "runtime-api/public-credentials", default-features = false}
Expand Down Expand Up @@ -133,6 +142,8 @@ try-runtime-cli = {git = "https://github.com/paritytech/substrate", default-feat
# Polkadot (with default disabled)
pallet-xcm = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
polkadot-parachain = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
rococo-runtime = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
polkadot-runtime-parachains = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
xcm = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
xcm-builder = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
xcm-executor = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38"}
Expand Down
Loading

0 comments on commit 98de546

Please sign in to comment.