Skip to content

Commit d0759fb

Browse files
kziemianekBillyWooogithub-actions[bot]
authored
Use whole unsigned VC as VC proof signature payload (#2404)
* Use whole unsigned VC as VC proof signature payload * fix fmt * fix ii-vc ts-test * improve test * remove VCRegistry and events * [benchmarking bot] Auto commit generated weights files (#2409) Co-authored-by: kziemianek <kziemianek@users.noreply.github.com> --------- Co-authored-by: BillyWooo <thedreamofbilly@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: kziemianek <kziemianek@users.noreply.github.com>
1 parent aaff988 commit d0759fb

File tree

22 files changed

+99
-1148
lines changed

22 files changed

+99
-1148
lines changed

pallets/vc-management/src/benchmarking.rs

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,11 @@ use sp_std::vec;
2828

2929
use test_utils::ias::consts::TEST8_MRENCLAVE;
3030
const USER_SEED: u32 = 9966;
31-
const VC_HASH: H256 = H256::zero();
32-
const VC_INDEX: H256 = H256::zero();
3331

3432
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
3533
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
3634
}
3735

38-
fn convert_u32_array_to_u8_array(u32_array: [u32; 8]) -> [u8; 32] {
39-
let mut u8_array = [0u8; 32];
40-
let mut index = 0;
41-
42-
for u32_element in &u32_array {
43-
let u8_slice = u32_element.to_le_bytes();
44-
u8_array[index..index + 4].copy_from_slice(&u8_slice);
45-
index += 4;
46-
}
47-
48-
u8_array
49-
}
50-
5136
benchmarks! {
5237
// Benchmark `add_delegatee`. There are no worst conditions. The benchmark showed that
5338
// execution time is constant irrespective of encrypted_data size.
@@ -78,44 +63,16 @@ benchmarks! {
7863
assert_last_event::<T>(Event::VCRequested{ account, shard, assertion }.into());
7964
}
8065

81-
// Benchmark `disable_vc`. There are no worst conditions. The benchmark showed that
82-
// execution time is constant irrespective of encrypted_data size.
83-
disable_vc {
84-
let account: T::AccountId = frame_benchmarking::account("TEST_A", 0u32, USER_SEED);
85-
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_A", 0u32, USER_SEED).into();
86-
let assertion = Assertion::A1;
87-
let req_ext_hash = H256::default();
88-
let tee_origin = T::TEECallOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
89-
VCManagement::<T>::vc_issued(tee_origin, identity, assertion, VC_INDEX, VC_HASH, req_ext_hash)?;
90-
}: _(RawOrigin::Signed(account.clone()), VC_INDEX)
91-
verify{
92-
assert_last_event::<T>(Event::VCDisabled{ account, index: VC_HASH }.into());
93-
}
94-
95-
// Benchmark `revoke_vc`. There are no worst conditions. The benchmark showed that
96-
// execution time is constant irrespective of encrypted_data size.
97-
revoke_vc {
98-
let account: T::AccountId = frame_benchmarking::account("TEST_A", 0u32, USER_SEED);
99-
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_A", 0u32, USER_SEED).into();
100-
let assertion = Assertion::A1;
101-
let req_ext_hash = H256::default();
102-
let tee_origin = T::TEECallOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
103-
VCManagement::<T>::vc_issued(tee_origin, identity, assertion, VC_INDEX, VC_HASH, req_ext_hash)?;
104-
}: _(RawOrigin::Signed(account.clone()), VC_INDEX)
105-
verify{
106-
assert_last_event::<T>(Event::VCRevoked{ account, index: VC_HASH }.into());
107-
}
108-
10966
// Benchmark `vc_issued`. There are no worst conditions. The benchmark showed that
11067
// execution time is constant irrespective of encrypted_data size.
11168
vc_issued {
11269
let call_origin = T::TEECallOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
11370
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_A", 0u32, USER_SEED).into();
11471
let assertion = Assertion::A1;
11572
let req_ext_hash = H256::default();
116-
}: _<T::RuntimeOrigin>(call_origin, identity.clone(), assertion.clone(), VC_INDEX, VC_HASH, req_ext_hash)
73+
}: _<T::RuntimeOrigin>(call_origin, identity.clone(), assertion.clone(), req_ext_hash)
11774
verify{
118-
assert_last_event::<T>(Event::VCIssued{ identity, assertion, index: VC_INDEX, req_ext_hash}.into());
75+
assert_last_event::<T>(Event::VCIssued{ identity, assertion, req_ext_hash}.into());
11976
}
12077

12178
// Benchmark `some_error`. There are no worst conditions. The benchmark showed that
@@ -199,48 +156,6 @@ benchmarks! {
199156
assert_last_event::<T>(Event::SchemaRevoked { account, shard, index: 0 }.into())
200157
}
201158

202-
// Benchmark `add_vc_registry_item`. There are no worst conditions. The benchmark showed that
203-
// execution time is constant irrespective of encrypted_data size.
204-
add_vc_registry_item {
205-
let account: T::AccountId = frame_benchmarking::account("TEST_A", 0u32, USER_SEED);
206-
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_B", 0u32, USER_SEED).into();
207-
VCManagement::<T>::set_admin(RawOrigin::Root.into(), account.clone())?;
208-
let assertion = Assertion::A1;
209-
}: _(RawOrigin::Signed(account.clone()), VC_INDEX, identity.clone(), assertion.clone(), VC_HASH)
210-
verify {
211-
assert_last_event::<T>(Event::VCRegistryItemAdded { identity, assertion, index: VC_INDEX }.into())
212-
}
213-
214-
// Benchmark `remove_vc_registry_item`. There are no worst conditions. The benchmark showed that
215-
// execution time is constant irrespective of encrypted_data size.
216-
remove_vc_registry_item {
217-
let account: T::AccountId = frame_benchmarking::account("TEST_A", 0u32, USER_SEED);
218-
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_B", 0u32, USER_SEED).into();
219-
VCManagement::<T>::set_admin(RawOrigin::Root.into(), account.clone())?;
220-
let assertion = Assertion::A1;
221-
VCManagement::<T>::add_vc_registry_item(RawOrigin::Signed(account.clone()).into(), VC_INDEX, identity, assertion, VC_HASH)?;
222-
}: _(RawOrigin::Signed(account), VC_INDEX)
223-
verify {
224-
assert_last_event::<T>(Event::VCRegistryItemRemoved { index: VC_INDEX }.into())
225-
}
226-
227-
// Benchmark `clear_vc_registry`.
228-
clear_vc_registry {
229-
let x in 0..100u32;
230-
let account: T::AccountId = frame_benchmarking::account("TEST_A", 0u32, USER_SEED);
231-
VCManagement::<T>::set_admin(RawOrigin::Root.into(), account.clone())?;
232-
let assertion = Assertion::A1;
233-
for i in 0..x {
234-
let seed = USER_SEED - i;
235-
let identity: Identity = frame_benchmarking::account::<AccountId>("TEST_A", 0u32, seed).into();
236-
let seed_hash_u8_32 = convert_u32_array_to_u8_array([seed; 8]);
237-
let hash: H256 = seed_hash_u8_32.into();
238-
VCManagement::<T>::add_vc_registry_item(RawOrigin::Signed(account.clone()).into(), hash, identity, assertion.clone(), VC_HASH)?;
239-
}
240-
}: _(RawOrigin::Signed(account))
241-
verify {
242-
assert_last_event::<T>(Event::VCRegistryCleared.into())
243-
}
244159
}
245160

246161
#[cfg(test)]

pallets/vc-management/src/lib.rs

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ use sp_core::H256;
3939
use sp_std::vec::Vec;
4040
use teerex_primitives::ShardIdentifier;
4141

42-
mod vc_context;
43-
pub use vc_context::*;
44-
4542
mod schema;
4643
pub use schema::*;
4744

@@ -73,12 +70,6 @@ pub mod pallet {
7370
type ExtrinsicWhitelistOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::AccountId>;
7471
}
7572

76-
// a map VCIndex -> VC context
77-
// TODO: to be removed in P-350
78-
#[pallet::storage]
79-
#[pallet::getter(fn vc_registry)]
80-
pub type VCRegistry<T: Config> = StorageMap<_, Blake2_128Concat, VCIndex, VCContext>;
81-
8273
// the admin account
8374
#[pallet::storage]
8475
#[pallet::getter(fn admin)]
@@ -87,7 +78,7 @@ pub mod pallet {
8778
// delegatees who can request (and receive) VCs on users' behalf,
8879
// some VCs can only be requested by delegatee accounts (e.g. A13)
8980
// delegatees and admins are different:
90-
// - admins are meant to manage the pallet state manually, e.g. schema, vcRegistry
81+
// - admins are meant to manage the pallet state manually, e.g. schema
9182
// - delegatees can request VCs for users, similar to `proxied account`
9283
#[pallet::storage]
9384
#[pallet::getter(fn delegatee)]
@@ -117,22 +108,11 @@ pub mod pallet {
117108
shard: ShardIdentifier,
118109
assertion: Assertion,
119110
},
120-
// a VC is disabled on chain
121-
VCDisabled {
122-
account: T::AccountId,
123-
index: VCIndex,
124-
},
125-
// a VC is revoked on chain
126-
VCRevoked {
127-
account: T::AccountId,
128-
index: VCIndex,
129-
},
130111
// event that should be triggered by TEECallOrigin
131112
// a VC is just issued
132113
VCIssued {
133114
identity: Identity,
134115
assertion: Assertion,
135-
index: VCIndex,
136116
req_ext_hash: H256,
137117
},
138118
// Admin account was changed
@@ -178,15 +158,6 @@ pub mod pallet {
178158
detail: ErrorDetail,
179159
req_ext_hash: H256,
180160
},
181-
VCRegistryItemAdded {
182-
identity: Identity,
183-
assertion: Assertion,
184-
index: VCIndex,
185-
},
186-
VCRegistryItemRemoved {
187-
index: VCIndex,
188-
},
189-
VCRegistryCleared,
190161
}
191162

192163
#[pallet::error]
@@ -276,38 +247,6 @@ pub mod pallet {
276247
Ok(().into())
277248
}
278249

279-
#[pallet::call_index(3)]
280-
#[pallet::weight(<T as Config>::WeightInfo::disable_vc())]
281-
pub fn disable_vc(origin: OriginFor<T>, index: VCIndex) -> DispatchResultWithPostInfo {
282-
let who = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
283-
VCRegistry::<T>::try_mutate(index, |context| {
284-
let mut c = context.take().ok_or(Error::<T>::VCNotExist)?;
285-
ensure!(
286-
Some(who.clone()).encode() == c.subject.to_account_id().encode(),
287-
Error::<T>::VCSubjectMismatch
288-
);
289-
ensure!(c.status == Status::Active, Error::<T>::VCAlreadyDisabled);
290-
c.status = Status::Disabled;
291-
*context = Some(c);
292-
Self::deposit_event(Event::VCDisabled { account: who, index });
293-
Ok(().into())
294-
})
295-
}
296-
297-
#[pallet::call_index(4)]
298-
#[pallet::weight(<T as Config>::WeightInfo::revoke_vc())]
299-
pub fn revoke_vc(origin: OriginFor<T>, index: VCIndex) -> DispatchResultWithPostInfo {
300-
let who = T::ExtrinsicWhitelistOrigin::ensure_origin(origin)?;
301-
let context = VCRegistry::<T>::get(index).ok_or(Error::<T>::VCNotExist)?;
302-
ensure!(
303-
Some(who.clone()).encode() == context.subject.to_account_id().encode(),
304-
Error::<T>::VCSubjectMismatch
305-
);
306-
VCRegistry::<T>::remove(index);
307-
Self::deposit_event(Event::VCRevoked { account: who, index });
308-
Ok(().into())
309-
}
310-
311250
#[pallet::call_index(5)]
312251
#[pallet::weight(<T as Config>::WeightInfo::set_admin())]
313252
pub fn set_admin(origin: OriginFor<T>, new: T::AccountId) -> DispatchResultWithPostInfo {
@@ -399,51 +338,6 @@ pub mod pallet {
399338
Ok(().into())
400339
}
401340

402-
#[pallet::call_index(10)]
403-
#[pallet::weight(<T as Config>::WeightInfo::add_vc_registry_item())]
404-
pub fn add_vc_registry_item(
405-
origin: OriginFor<T>,
406-
index: VCIndex,
407-
identity: Identity,
408-
assertion: Assertion,
409-
hash: H256,
410-
) -> DispatchResultWithPostInfo {
411-
let sender = ensure_signed(origin)?;
412-
ensure!(Some(sender) == Self::admin(), Error::<T>::RequireAdmin);
413-
ensure!(!VCRegistry::<T>::contains_key(index), Error::<T>::VCAlreadyExists);
414-
VCRegistry::<T>::insert(
415-
index,
416-
VCContext::new(identity.clone(), assertion.clone(), hash),
417-
);
418-
Self::deposit_event(Event::VCRegistryItemAdded { identity, assertion, index });
419-
Ok(().into())
420-
}
421-
422-
#[pallet::call_index(11)]
423-
#[pallet::weight(<T as Config>::WeightInfo::remove_vc_registry_item())]
424-
pub fn remove_vc_registry_item(
425-
origin: OriginFor<T>,
426-
index: VCIndex,
427-
) -> DispatchResultWithPostInfo {
428-
let sender = ensure_signed(origin)?;
429-
ensure!(Some(sender) == Self::admin(), Error::<T>::RequireAdmin);
430-
let _ = VCRegistry::<T>::get(index).ok_or(Error::<T>::VCNotExist)?;
431-
VCRegistry::<T>::remove(index);
432-
Self::deposit_event(Event::VCRegistryItemRemoved { index });
433-
Ok(().into())
434-
}
435-
436-
#[pallet::call_index(12)]
437-
#[pallet::weight(<T as Config>::WeightInfo::clear_vc_registry(u32::max_value()))]
438-
pub fn clear_vc_registry(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
439-
let sender = ensure_signed(origin)?;
440-
ensure!(Some(sender) == Self::admin(), Error::<T>::RequireAdmin);
441-
// If more than u32 max, the map itself is overflow, so no worry
442-
let _ = VCRegistry::<T>::clear(u32::max_value(), None);
443-
Self::deposit_event(Event::VCRegistryCleared);
444-
Ok(Pays::No.into())
445-
}
446-
447341
/// ---------------------------------------------------
448342
/// The following extrinsics are supposed to be called by TEE only
449343
/// ---------------------------------------------------
@@ -453,17 +347,10 @@ pub mod pallet {
453347
origin: OriginFor<T>,
454348
identity: Identity,
455349
assertion: Assertion,
456-
index: H256,
457-
hash: H256,
458350
req_ext_hash: H256,
459351
) -> DispatchResultWithPostInfo {
460352
let _ = T::TEECallOrigin::ensure_origin(origin)?;
461-
ensure!(!VCRegistry::<T>::contains_key(index), Error::<T>::VCAlreadyExists);
462-
VCRegistry::<T>::insert(
463-
index,
464-
VCContext::new(identity.clone(), assertion.clone(), hash),
465-
);
466-
Self::deposit_event(Event::VCIssued { identity, assertion, index, req_ext_hash });
353+
Self::deposit_event(Event::VCIssued { identity, assertion, req_ext_hash });
467354
Ok(Pays::No.into())
468355
}
469356

pallets/vc-management/src/schema.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717
// VC Schema
1818
// According to https://w3c-ccg.github.io/vc-json-schemas/, it defines JSON Schema for W3C Verifiable Credential.
1919

20-
use crate::{vc_context::Status, Config};
20+
use crate::Config;
2121
use codec::{Decode, Encode, MaxEncodedLen};
2222
use core_primitives::{SchemaContentString, SchemaIdString};
2323
use scale_info::TypeInfo;
2424
use sp_std::vec::Vec;
2525

26+
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
27+
pub enum Status {
28+
#[codec(index = 0)]
29+
Active,
30+
#[codec(index = 1)]
31+
Disabled,
32+
// Revoked, // commented out for now, we can delete the VC entry when revoked
33+
}
34+
2635
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
2736
#[scale_info(skip_type_params(T))]
2837
#[codec(mel_bound())]

0 commit comments

Comments
 (0)