Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding abstractions for the omni-account in the worker #3116

Merged
merged 48 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b4c24cf
adding omni-account primitives
silva-fj Oct 4, 2024
26ecf05
updating omni-account pallet to use new primitives
silva-fj Oct 4, 2024
471a3ea
cleaning up identity primitives
silva-fj Oct 4, 2024
19db50c
adding new primitives for storage keys
silva-fj Oct 4, 2024
49f8ef2
adding omni-account litentry core
silva-fj Oct 4, 2024
de03b6d
preparing IDGraphs in-memory store
silva-fj Oct 4, 2024
288cad7
adding initial implementation of id_graphs_repository
silva-fj Oct 4, 2024
8f7f119
fixing fmt
silva-fj Oct 4, 2024
7159024
feat: refactor IDGraphs handling and repository methods
silva-fj Oct 5, 2024
9fba6d1
injecting OnChainEncryptionKeyRepository and parentchain header to the
silva-fj Oct 7, 2024
17845b8
refactoring omni-account core, updating names and structures
silva-fj Oct 8, 2024
50375d8
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 8, 2024
53b525d
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 8, 2024
252e337
fixing fmt issues
silva-fj Oct 8, 2024
190dfb0
fixing taplo issues
silva-fj Oct 8, 2024
dddd127
fixing core primitives dependencies
silva-fj Oct 8, 2024
597379d
updating litentry_primitives and importing new types directly
silva-fj Oct 9, 2024
45cb0ee
refactoring name
silva-fj Oct 9, 2024
d09989e
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 9, 2024
14e8e0d
cleaning up unused dependencies
silva-fj Oct 9, 2024
e62f5c9
fix: allow clippy::too_many_arguments lint
silva-fj Oct 9, 2024
12cb305
updating comment
silva-fj Oct 9, 2024
ad058bb
updating bitacross executor types
silva-fj Oct 9, 2024
ab7e931
Merge branch 'dev' into p-1086-transition-to-ram-idgraph-use-in-worker
silva-fj Oct 9, 2024
1da6286
fixing fmt issue
silva-fj Oct 9, 2024
32ffc5e
fixing tests
silva-fj Oct 9, 2024
2fcf96c
chore: add GPL license headers to source files
silva-fj Oct 10, 2024
039bbea
removing unused import
silva-fj Oct 10, 2024
5fc3874
refactor: update get_storage_keys to accept optional header
silva-fj Oct 10, 2024
cdac91f
cleaning up imports
silva-fj Oct 10, 2024
f68aa0a
updating bitacross on_chain_ocall
silva-fj Oct 10, 2024
ceb899a
Revert "updating bitacross executor types"
silva-fj Oct 10, 2024
5ef031c
Revert "injecting OnChainEncryptionKeyRepository and parentchain head…
silva-fj Oct 10, 2024
205a71b
Revert "fixing tests"
silva-fj Oct 10, 2024
8e2f0c5
cleaning up dependencies
silva-fj Oct 10, 2024
2c2fdd7
Merge branch 'dev' into p-1086-transition-to-ram-idgraph-use-in-worker
silva-fj Oct 10, 2024
78ced91
cleaning up dependencies
silva-fj Oct 10, 2024
34288c0
removing dead code
silva-fj Oct 10, 2024
4c210a9
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 11, 2024
9a1442b
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 12, 2024
f00ad0b
cleaning up dependencies
silva-fj Oct 12, 2024
92cf328
fixing fmt
silva-fj Oct 12, 2024
6ef64ac
making types simpler as hash can be computed in all members
silva-fj Oct 15, 2024
e2b3758
removing unused imports
silva-fj Oct 15, 2024
3b2207a
Merge branch 'dev' into p-1086-transition-to-ram-idgraph-use-in-worker
silva-fj Oct 15, 2024
e005244
Merge remote-tracking branch 'origin/dev' into p-1086-transition-to-r…
silva-fj Oct 16, 2024
6986217
feat: update get methods to return Option type
silva-fj Oct 16, 2024
0595975
updating trait
silva-fj Oct 16, 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
14 changes: 7 additions & 7 deletions common/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ version = '0.1.0'
[dependencies]
base58 = { version = "0.2", default-features = false }
base64 = { version = "0.13", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive", "max-encoded-len"] }
strum = { version = "0.26", default-features = false }
strum_macros = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "=1.0.120", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
der = { version = "0.6.0", default-features = false }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive", "max-encoded-len"] }
ring = { version = "0.16.20", default-features = false, features = ["alloc"] }
x509-cert = { version = "0.1.0", default-features = false, features = ["alloc"] }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "=1.0.120", default-features = false }
strum = { version = "0.26", default-features = false }
strum_macros = { version = "0.26", default-features = false }
webpki = { version = "=0.102.0-alpha.3", git = "https://github.com/rustls/webpki", rev = "da923ed", package = "rustls-webpki", default-features = false, features = ["alloc", "ring"] }
x509-cert = { version = "0.1.0", default-features = false, features = ["alloc"] }

frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-evm = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.1.0", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion common/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ pub use assertion::Assertion;
pub mod identity;
pub use identity::*;

mod omni_account;
pub mod omni_account;
pub use omni_account::*;

extern crate alloc;
extern crate core;
use alloc::{format, str, str::FromStr, string::String, vec, vec::Vec};
use sp_runtime::{traits::ConstU32, BoundedVec};

Expand Down
2 changes: 0 additions & 2 deletions common/primitives/core/src/teebag/sgx_verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
//!
//! * https://download.01.org/intel-sgx/linux-1.5/docs/Intel_SGX_Developer_Guide.pdf

pub extern crate alloc;

use self::{
collateral::{EnclaveIdentity, TcbInfo},
netscape_comment::NetscapeComment,
Expand Down
1 change: 0 additions & 1 deletion parachain/Cargo.lock

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

2 changes: 1 addition & 1 deletion parachain/pallets/omni-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ scale-info = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-core-hashing = { workspace = true }

sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
Expand Down
17 changes: 17 additions & 0 deletions tee-worker/Cargo.lock

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

2 changes: 2 additions & 0 deletions tee-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ members = [
"identity/litentry/core/native-task/sender",
"identity/litentry/core/native-task/receiver",
"identity/litentry/core/identity-verification",
"identity/litentry/core/omni-account",
"identity/litentry/core/stf-task/sender",
"identity/litentry/core/stf-task/receiver",
"identity/litentry/core/service",
Expand Down Expand Up @@ -300,6 +301,7 @@ lc-stf-task-sender = { path = "identity/litentry/core/stf-task/sender", default-
lc-stf-task-receiver = { path = "identity/litentry/core/stf-task/receiver", default-features = false }
lc-vc-task-sender = { path = "identity/litentry/core/vc-task/sender", default-features = false }
lc-vc-task-receiver = { path = "identity/litentry/core/vc-task/receiver", default-features = false }
lc-omni-account = { path = "identity/app-libs/omni-account", default-features = false }
lc-native-task-sender = { path = "identity/litentry/core/native-task/sender", default-features = false }
lc-native-task-receiver = { path = "identity/litentry/core/native-task/receiver", default-features = false }

Expand Down
2 changes: 2 additions & 0 deletions tee-worker/bitacross/enclave-runtime/Cargo.lock

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

10 changes: 7 additions & 3 deletions tee-worker/bitacross/enclave-runtime/src/ocall/on_chain_ocall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ impl EnclaveOnChainOCallApi for OcallApi {
Ok(storage_entries)
}

fn get_storage_keys(&self, key_prefix: Vec<u8>) -> Result<Vec<Vec<u8>>> {
// always using the latest state - we need to support optional header
let requests = vec![WorkerRequest::ChainStorageKeys(key_prefix, None)];
fn get_storage_keys<H: Header<Hash = H256>>(
&self,
key_prefix: Vec<u8>,
header: Option<&H>,
) -> Result<Vec<Vec<u8>>> {
let header_hash = header.map(|h| h.hash());
let requests = vec![WorkerRequest::ChainStorageKeys(key_prefix, header_hash)];

let responses: Vec<Vec<Vec<u8>>> = self
.worker_request::<Vec<u8>>(requests, &ParentchainId::Litentry)?
Expand Down
6 changes: 5 additions & 1 deletion tee-worker/common/core-primitives/ocall-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ pub trait EnclaveOnChainOCallApi: Clone + Send + Sync {

// Litentry
// given a key prefix, get all storage keys
fn get_storage_keys(&self, key_prefix: Vec<u8>) -> Result<Vec<Vec<u8>>>;
fn get_storage_keys<H: Header<Hash = H256>>(
&self,
key_prefix: Vec<u8>,
header: Option<&H>,
) -> Result<Vec<Vec<u8>>>;
}

/// Trait for sending metric updates.
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/common/core-primitives/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sp-trie = { workspace = true }

itp-types = { workspace = true }

litentry-hex-utils = { workspace = true }

[dev-dependencies]
sp-state-machine = { workspace = true, features = ["std"] }

Expand Down
16 changes: 14 additions & 2 deletions tee-worker/common/core-primitives/storage/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

*/

use codec::Encode;
use alloc::{string::String, vec::Vec};
use codec::{Decode, Encode};
use frame_metadata::v14::StorageHasher;
use sp_std::vec::Vec;
use frame_support::{Blake2_128Concat, ReversibleStorageHasher};
use litentry_hex_utils::decode_hex;

pub fn storage_value_key(module_prefix: &str, storage_prefix: &str) -> Vec<u8> {
let mut bytes = sp_core::twox_128(module_prefix.as_bytes()).to_vec();
Expand All @@ -37,6 +39,16 @@ pub fn storage_map_key<K: Encode>(
bytes
}

pub fn extract_blake2_128concat_key<K: Decode>(raw_storage_key: &[u8]) -> Option<K> {
let mut raw_key = Blake2_128Concat::reverse(raw_storage_key);
K::decode(&mut raw_key).ok()
}

pub fn decode_storage_key(raw_key: Vec<u8>) -> Option<Vec<u8>> {
let hex_key = String::decode(&mut raw_key.as_slice()).unwrap_or_default();
decode_hex(hex_key).ok()
}

pub fn storage_double_map_key<K: Encode, Q: Encode>(
module_prefix: &str,
storage_prefix: &str,
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/common/core-primitives/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam
#[cfg(all(not(feature = "std"), feature = "sgx"))]
extern crate sgx_tstd as std;

extern crate alloc;

pub use error::Error;
pub use frame_metadata::v14::StorageHasher;
pub use keys::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ impl EnclaveOnChainOCallApi for OnchainMock {
Ok(entries)
}

fn get_storage_keys(&self, _key_prefix: Vec<u8>) -> Result<Vec<Vec<u8>>, itp_ocall_api::Error> {
fn get_storage_keys<H: HeaderTrait<Hash = H256>>(
&self,
_key_prefix: Vec<u8>,
_header: Option<&H>,
) -> Result<Vec<Vec<u8>>, itp_ocall_api::Error> {
Ok(Default::default())
}
}
Expand Down
1 change: 1 addition & 0 deletions tee-worker/common/litentry/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub use parentchain_primitives::{
},
decl_rsa_request,
identity::*,
omni_account::*,
teebag::*,
AccountId as ParentchainAccountId, Balance as ParentchainBalance,
BlockNumber as ParentchainBlockNumber, ErrorDetail, ErrorString, Hash as ParentchainHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ itp-node-api = { workspace = true }
itp-ocall-api = { workspace = true }
itp-sgx-crypto = { workspace = true }
itp-sgx-externalities = { workspace = true }
itp-sgx-io = { workspace = true }
itp-stf-interface = { workspace = true }
itp-stf-primitives = { workspace = true }
itp-stf-state-handler = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/identity/enclave-runtime/Cargo.lock

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

10 changes: 7 additions & 3 deletions tee-worker/identity/enclave-runtime/src/ocall/on_chain_ocall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ impl EnclaveOnChainOCallApi for OcallApi {
Ok(storage_entries)
}

fn get_storage_keys(&self, key_prefix: Vec<u8>) -> Result<Vec<Vec<u8>>> {
// always using the latest state - we need to support optional header
let requests = vec![WorkerRequest::ChainStorageKeys(key_prefix, None)];
fn get_storage_keys<H: Header<Hash = H256>>(
&self,
key_prefix: Vec<u8>,
header: Option<&H>,
) -> Result<Vec<Vec<u8>>> {
let header_hash = header.map(|h| h.hash());
let requests = vec![WorkerRequest::ChainStorageKeys(key_prefix, header_hash)];

let responses: Vec<Vec<Vec<u8>>> = self
.worker_request::<Vec<u8>>(requests, &ParentchainId::Litentry)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl EnclaveOnChainOCallApi for ProposeToImportOCallApi {
todo!()
}

fn get_storage_keys(&self, _key_prefix: Vec<u8>) -> Result<Vec<Vec<u8>>> {
fn get_storage_keys<H: ParentchainHeaderTrait<Hash = H256>>(
&self,
_key_prefix: Vec<u8>,
_header: Option<&H>,
) -> Result<Vec<Vec<u8>>> {
todo!()
}
}
Expand Down
3 changes: 2 additions & 1 deletion tee-worker/identity/litentry/core/assertion-build/src/a13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::*;
use codec::Decode;
use frame_support::storage::storage_prefix;
use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_types::parentchain::Header;
use lc_credentials::IssuerRuntimeVersion;
use litentry_primitives::Address32;

Expand All @@ -39,7 +40,7 @@ pub fn build<O: EnclaveOnChainOCallApi>(
debug!("Assertion A13 build, who: {:?}", account_id_to_string(&who));

let key_prefix = storage_prefix(b"VCManagement", b"Delegatee");
let response = ocall_api.get_storage_keys(key_prefix.into()).map_err(|_| {
let response = ocall_api.get_storage_keys::<Header>(key_prefix.into(), None).map_err(|_| {
Error::RequestVCFailed(Assertion::A13(who.clone()), ErrorDetail::ParseError)
})?;
let keys: Vec<String> = response
Expand Down
32 changes: 32 additions & 0 deletions tee-worker/identity/litentry/core/omni-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
authors = ["Trust Computing GmbH <[email protected]>"]
edition = "2021"
name = "lc-omni-account"
version = "0.1.0"

[dependencies]
litentry-primitives = { workspace = true }

itp-ocall-api = { workspace = true }
itp-storage = { workspace = true }
itp-types = { workspace = true }

frame-support = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
sp-core = { workspace = true }

sgx_tstd = { workspace = true, features = ["net", "thread"], optional = true }

[features]
default = ["std"]
std = [
"litentry-primitives/std",
"frame-support/std",
"itp-storage/std",
"itp-types/std",
]
sgx = [
"litentry-primitives/sgx",
"sgx_tstd",
]
Loading
Loading