Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bddc86f
Unique leaf instead of key + value
ntn-x2 Jan 10, 2024
15253bc
Refactor merkle proof verification into single function
ntn-x2 Jan 10, 2024
555927f
More refactoring
ntn-x2 Jan 10, 2024
e142c8a
Refactor compiling
ntn-x2 Jan 11, 2024
470dd53
A lot of progress
ntn-x2 Jan 11, 2024
147ffbc
Compiling again
ntn-x2 Jan 11, 2024
b1b660d
Compiling again
ntn-x2 Jan 11, 2024
37ffe78
Wip
ntn-x2 Jan 11, 2024
bcdaa98
kilt-dip-primitives compiling
ntn-x2 Jan 12, 2024
dca9930
Kilt provider template compiling
ntn-x2 Jan 12, 2024
2f8e779
Consumer template compiling
ntn-x2 Jan 12, 2024
be28412
Whole project compiling
ntn-x2 Jan 12, 2024
91e9f46
New design in progress
ntn-x2 Jan 12, 2024
b5398d1
Refactor
ntn-x2 Jan 15, 2024
8c147c4
Compiling
ntn-x2 Jan 15, 2024
f62c0fc
The whole thing compiling
ntn-x2 Jan 15, 2024
582e2c1
Compiling again
ntn-x2 Jan 15, 2024
9b79d46
Removing bounds from proofs
ntn-x2 Jan 15, 2024
d6647a0
wip
ntn-x2 Jan 15, 2024
a03f576
Project compiling
ntn-x2 Jan 16, 2024
3c88ad5
Debug assertions
ntn-x2 Jan 16, 2024
cb5a4af
Merge commit 'b8a22b85fad24d88c2849f6430f8b6019522fd25' into aa/dip-i…
ntn-x2 Jan 16, 2024
cb6b385
Minor chores
ntn-x2 Jan 16, 2024
290f7cd
Before refactoring with runtime
ntn-x2 Jan 16, 2024
1c70fc4
COMPILING
ntn-x2 Jan 16, 2024
d266720
Comments addressed
ntn-x2 Jan 16, 2024
c59b30f
Staging changes
ntn-x2 Jan 17, 2024
82160d2
Primitives compiling again
ntn-x2 Jan 23, 2024
14e5a53
Runtime common compiling
ntn-x2 Jan 23, 2024
51d4570
Project compiling without benchmarking feature
ntn-x2 Jan 23, 2024
dc271c7
Project compiling with all features enabled
ntn-x2 Jan 23, 2024
a520335
Benchmarks passing for consumer template
ntn-x2 Jan 26, 2024
e4e853a
Remove benchmarks from verifier code
ntn-x2 Jan 26, 2024
86fbde5
Make relaychain same as parachain verifier
ntn-x2 Jan 26, 2024
9da230e
Add valid_unlid_until to signed payload
ntn-x2 Jan 31, 2024
7c9645a
Fix regression bug
ntn-x2 Feb 9, 2024
d63ee4a
Increase limits for Merkle proof leaves size
ntn-x2 Feb 9, 2024
20291a1
Add state proof verification function with custom decoder
ntn-x2 Feb 9, 2024
f20d24e
Refactor visibility of struct fields
ntn-x2 Feb 9, 2024
c02de70
Fix dependencies
ntn-x2 Feb 9, 2024
c5aa5a9
Rename intermediate structs
ntn-x2 Feb 9, 2024
a5e31e6
Merge branch 'develop' into aa/dip-improvements
ntn-x2 Feb 9, 2024
2219847
Merge branch 'develop' into aa/dip-improvements
ntn-x2 Feb 22, 2024
72fc3cb
Add comment about relaychain being Rococo
ntn-x2 Feb 22, 2024
51ac902
Add comments about 0 value
ntn-x2 Feb 22, 2024
aea6b93
Grammar fix
ntn-x2 Feb 22, 2024
e20c96d
Add copyright notice about Parity source code
ntn-x2 Feb 22, 2024
287116e
Fix benchmarking feature
ntn-x2 Feb 22, 2024
493fda8
Fix docs generation
ntn-x2 Feb 22, 2024
1f18d8d
Add unit tests for pallet-dip-provider pallet
ntn-x2 Feb 12, 2024
03984a4
Add unit tests for the identity retriever implementation
ntn-x2 Feb 13, 2024
4f2ad53
Extrapolate runtime-common mock runtime
ntn-x2 Feb 13, 2024
b78a8a9
Finalize refactoring and fix block imports
ntn-x2 Feb 13, 2024
0c20c20
One more refactor
ntn-x2 Feb 13, 2024
cc32e80
Initial setup for the identity commitment generator tests
ntn-x2 Feb 13, 2024
788a1ed
Fix commitment generator tests
ntn-x2 Feb 14, 2024
836bdca
Unit tests for commitment generation v0
ntn-x2 Feb 14, 2024
fce4951
More refactoring before proof generation tests
ntn-x2 Feb 14, 2024
a8fb2c0
Add unit test for full linked info proof generation
ntn-x2 Feb 14, 2024
51e2f12
Unit tests for Merkle proof generation completed
ntn-x2 Feb 15, 2024
dc30165
Replace NoopHook with ()
ntn-x2 Feb 15, 2024
2f047f4
Initial struct for deposit handling unit testing
ntn-x2 Feb 15, 2024
96e8f60
Complete on_identity_committed unit tests. Skeleton for on_commitment…
ntn-x2 Feb 19, 2024
6e1ae4a
FixedDepositCollectorViaDepositsPallet unit tests complete
ntn-x2 Feb 20, 2024
5048dd0
Add skeleton for pallet-deposit-storage pallet unit testing
ntn-x2 Feb 20, 2024
4681b0d
reclaim_deposit tests for pallet-deposit-storage complete
ntn-x2 Feb 21, 2024
029f983
Complete unit tests for pallet-deposit-storage
ntn-x2 Feb 21, 2024
1067c10
Move deposit storage hooks to runtime-common and add unit tests
ntn-x2 Feb 21, 2024
93fb67d
Refactor ExtBuilders
ntn-x2 Feb 21, 2024
f82c686
Migrate tests from reserve to hold
ntn-x2 Feb 21, 2024
729eaf8
One-function-one-test-module
ntn-x2 Feb 21, 2024
c728053
Minor final chores
ntn-x2 Feb 22, 2024
294ae7f
Merge commit '62a1373d20cae10a72e67973f5f6392052a6eaee' into aa/dip-u…
ntn-x2 Feb 22, 2024
e5dff16
Post-merge fixes
ntn-x2 Feb 22, 2024
bff8f78
Make DID and ACCOUNT_ID differ
ntn-x2 Mar 1, 2024
8b68008
Replace match with if let
ntn-x2 Mar 1, 2024
9ab225d
Split call tests for pallet-dip-provider into multiple files
ntn-x2 Mar 1, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

46 changes: 42 additions & 4 deletions crates/kilt-dip-primitives/src/merkle/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ pub struct TimeBoundDidSignature<BlockNumber> {
pub(crate) valid_until: BlockNumber,
}

impl<BlockNumber> TimeBoundDidSignature<BlockNumber> {
pub fn new(signature: DidSignature, valid_until: BlockNumber) -> Self {
Self { signature, valid_until }
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<BlockNumber, Context> kilt_support::traits::GetWorstCase<Context> for TimeBoundDidSignature<BlockNumber>
where
Expand Down Expand Up @@ -770,6 +776,38 @@ pub struct DipDidProofWithVerifiedSubjectCommitment<
pub(crate) signature: TimeBoundDidSignature<ConsumerBlockNumber>,
}

impl<
Commitment,
KiltDidKeyId,
KiltAccountId,
KiltBlockNumber,
KiltWeb3Name,
KiltLinkableAccountId,
ConsumerBlockNumber,
>
DipDidProofWithVerifiedSubjectCommitment<
Commitment,
KiltDidKeyId,
KiltAccountId,
KiltBlockNumber,
KiltWeb3Name,
KiltLinkableAccountId,
ConsumerBlockNumber,
>
{
pub fn new(
dip_commitment: Commitment,
dip_proof: DidMerkleProof<KiltDidKeyId, KiltAccountId, KiltBlockNumber, KiltWeb3Name, KiltLinkableAccountId>,
signature: TimeBoundDidSignature<ConsumerBlockNumber>,
) -> Self {
Self {
dip_commitment,
dip_proof,
signature,
}
}
}

impl<
Commitment,
KiltDidKeyId,
Expand Down Expand Up @@ -1164,7 +1202,7 @@ impl<
}

/// Relationship of a key to a DID Document.
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)]
pub enum DidKeyRelationship {
Encryption,
Verification(DidVerificationKeyRelationship),
Expand Down Expand Up @@ -1275,7 +1313,7 @@ where

/// The details of a DID key after it has been successfully verified in a Merkle
/// proof.
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)]
pub struct RevealedDidKey<KeyId, BlockNumber, AccountId> {
/// The key ID, according to the provider's definition.
pub id: KeyId,
Expand All @@ -1288,7 +1326,7 @@ pub struct RevealedDidKey<KeyId, BlockNumber, AccountId> {

/// The details of a web3name after it has been successfully verified in a
/// Merkle proof.
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)]
pub struct RevealedWeb3Name<Web3Name, BlockNumber> {
/// The web3name.
pub web3_name: Web3Name,
Expand All @@ -1299,5 +1337,5 @@ pub struct RevealedWeb3Name<Web3Name, BlockNumber> {

/// The details of an account after it has been successfully verified in a
/// Merkle proof.
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)]
pub struct RevealedAccountId<AccountId>(pub AccountId);
2 changes: 1 addition & 1 deletion dip-template/runtimes/dip-consumer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ std = [
"pallet-collator-selection/std",
"parachain-info/std",
"rococo-runtime/std",
"frame-benchmarking/std",
"frame-benchmarking?/std",
"frame-system-benchmarking?/std",
]

Expand Down
2 changes: 1 addition & 1 deletion pallets/did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ pub mod pallet {
/// Deletes DID details from storage, including its linked service
/// endpoints, adds the identifier to the blacklisted DIDs and frees the
/// deposit.
pub(crate) fn delete_did(did_subject: DidIdentifierOf<T>, endpoints_to_remove: u32) -> DispatchResult {
pub fn delete_did(did_subject: DidIdentifierOf<T>, endpoints_to_remove: u32) -> DispatchResult {
let current_endpoints_count = DidEndpointsCount::<T>::get(&did_subject);
ensure!(
current_endpoints_count <= endpoints_to_remove,
Expand Down
177 changes: 177 additions & 0 deletions pallets/pallet-deposit-storage/src/deposit/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// KILT Blockchain – https://botlabs.org
// Copyright (C) 2019-2024 BOTLabs GmbH

// The KILT Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The KILT Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// If you feel like getting in touch with us, you can do so at [email protected]

use frame_support::{
construct_runtime,
sp_runtime::{
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
AccountId32,
},
traits::{ConstU128, ConstU16, ConstU32, ConstU64, Currency, Everything, Get},
};
use frame_system::{mocking::MockBlock, EnsureSigned};
use pallet_dip_provider::{DefaultIdentityCommitmentGenerator, DefaultIdentityProvider, IdentityCommitmentVersion};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

use crate::{
self as storage_deposit_pallet, DepositEntryOf, DepositKeyOf, FixedDepositCollectorViaDepositsPallet, Pallet,
};

pub(crate) type Balance = u128;

#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug, Default)]
pub enum DepositNamespaces {
#[default]
ExampleNamespace,
}

impl Get<DepositNamespaces> for DepositNamespaces {
fn get() -> DepositNamespaces {
Self::ExampleNamespace
}
}

construct_runtime!(
pub struct TestRuntime {
System: frame_system,
Balances: pallet_balances,
DipProvider: pallet_dip_provider,
StorageDepositPallet: storage_deposit_pallet,
}
);

pub(crate) const SUBJECT: AccountId32 = AccountId32::new([100u8; 32]);
pub(crate) const SUBMITTER: AccountId32 = AccountId32::new([200u8; 32]);

impl frame_system::Config for TestRuntime {
type AccountData = pallet_balances::AccountData<Balance>;
type AccountId = AccountId32;
type BaseCallFilter = Everything;
type Block = MockBlock<TestRuntime>;
type BlockHashCount = ConstU64<256>;
type BlockLength = ();
type BlockWeights = ();
type DbWeight = ();
type Hash = H256;
type Hashing = BlakeTwo256;
type Lookup = IdentityLookup<Self::AccountId>;
type MaxConsumers = ConstU32<16>;
type Nonce = u64;
type OnKilledAccount = ();
type OnNewAccount = ();
type OnSetCode = ();
type PalletInfo = PalletInfo;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SS58Prefix = ConstU16<1>;
type SystemWeightInfo = ();
type Version = ();
}

impl pallet_balances::Config for TestRuntime {
type FreezeIdentifier = RuntimeFreezeReason;
type RuntimeHoldReason = RuntimeHoldReason;
type MaxFreezes = ConstU32<50>;
type MaxHolds = ConstU32<50>;
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU128<500>;
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
}

pub(crate) type DepositCollectorHook<Runtime> = FixedDepositCollectorViaDepositsPallet<
DepositNamespaces,
ConstU128<1_000>,
(
<Runtime as pallet_dip_provider::Config>::Identifier,
AccountId32,
IdentityCommitmentVersion,
),
>;

impl pallet_dip_provider::Config for TestRuntime {
type CommitOrigin = AccountId32;
type CommitOriginCheck = EnsureSigned<AccountId32>;
type Identifier = AccountId32;
type IdentityCommitmentGenerator = DefaultIdentityCommitmentGenerator<u32>;
type IdentityProvider = DefaultIdentityProvider<u32>;
type ProviderHooks = DepositCollectorHook<Self>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

impl crate::Config for TestRuntime {
type CheckOrigin = EnsureSigned<Self::AccountId>;
type Currency = Balances;
type DepositHooks = ();
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type MaxKeyLength = ConstU32<256>;
type Namespace = DepositNamespaces;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHooks = ();
type WeightInfo = ();
}

#[derive(Default)]
pub(crate) struct ExtBuilder(
Vec<(AccountId32, Balance)>,
Vec<(DepositKeyOf<TestRuntime>, DepositEntryOf<TestRuntime>)>,
);

impl ExtBuilder {
pub(crate) fn with_balances(mut self, balances: Vec<(AccountId32, Balance)>) -> Self {
self.0 = balances;
self
}

pub(crate) fn with_deposits(
mut self,
deposits: Vec<(DepositKeyOf<TestRuntime>, DepositEntryOf<TestRuntime>)>,
) -> Self {
self.1 = deposits;
self
}

pub(crate) fn build(self) -> sp_io::TestExternalities {
let mut ext = sp_io::TestExternalities::default();

ext.execute_with(|| {
for (account, balance) in self.0 {
Balances::make_free_balance_be(&account, balance);
}

for (deposit_key, deposit_entry) in self.1 {
// Add existential deposit + deposit amount.
Balances::make_free_balance_be(&deposit_entry.deposit.owner, 500 + deposit_entry.deposit.amount);
Pallet::<TestRuntime>::add_deposit(DepositNamespaces::get(), deposit_key, deposit_entry).unwrap();
}
});

ext
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ use sp_std::marker::PhantomData;

use crate::{BalanceOf, Config, Error, HoldReason, Pallet};

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

/// Details associated to an on-chain deposit.
#[derive(Clone, Debug, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)]
pub struct DepositEntry<AccountId, Balance, Reason> {
Expand Down Expand Up @@ -107,11 +112,12 @@ where
},
reason: HoldReason::Deposit.into(),
};
Pallet::<Runtime>::add_deposit(namespace, key, deposit_entry).map_err(|e| match e {
pallet_error if pallet_error == DispatchError::from(Error::<Runtime>::DepositExisting) => {
Pallet::<Runtime>::add_deposit(namespace, key, deposit_entry).map_err(|e| {
if e == DispatchError::from(Error::<Runtime>::DepositExisting) {
FixedDepositCollectorViaDepositsPalletError::DepositAlreadyTaken
}
_ => {
} else if e == DispatchError::from(Error::<Runtime>::FailedToHold) {
FixedDepositCollectorViaDepositsPalletError::FailedToHold
} else {
log::error!(
"Error {:#?} should not be generated inside `on_identity_committed` hook.",
e
Expand Down Expand Up @@ -140,11 +146,15 @@ where
);
FixedDepositCollectorViaDepositsPalletError::Internal
})?;
Pallet::<Runtime>::remove_deposit(&namespace, &key, None).map_err(|e| match e {
pallet_error if pallet_error == DispatchError::from(Error::<Runtime>::DepositNotFound) => {
// We don't set any expected owner for the deposit on purpose, since this hook
// assumes the dip-provider pallet has performed all the access control logic
// necessary.
Pallet::<Runtime>::remove_deposit(&namespace, &key, None).map_err(|e| {
if e == DispatchError::from(Error::<Runtime>::DepositNotFound) {
FixedDepositCollectorViaDepositsPalletError::DepositNotFound
}
_ => {
} else if e == DispatchError::from(Error::<Runtime>::FailedToRelease) {
FixedDepositCollectorViaDepositsPalletError::FailedToRelease
} else {
log::error!(
"Error {:#?} should not be generated inside `on_commitment_removed` hook.",
e
Expand Down
20 changes: 20 additions & 0 deletions pallets/pallet-deposit-storage/src/deposit/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// KILT Blockchain – https://botlabs.org
// Copyright (C) 2019-2024 BOTLabs GmbH

// The KILT Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The KILT Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// If you feel like getting in touch with us, you can do so at [email protected]

mod on_commitment_removed;
mod on_identity_committed;
Loading