Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into p-1322-set-the-actual-…
Browse files Browse the repository at this point in the history
…mrenclave-to-the-rpc-server-context
  • Loading branch information
silva-fj committed Feb 17, 2025
2 parents 41f902f + c43f180 commit 944defe
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 64 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

<div align="center">

![](https://res.cloudinary.com/brandpad/image/upload/c_scale,dpr_auto,f_auto,w_768/v1673016042/19618/parachain-logo-color-black-t)
![Image](https://github.com/user-attachments/assets/63bf12cf-f6cd-4021-8806-80405399c7cb)

[![general ci](https://github.com/litentry/litentry-parachain/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/litentry/litentry-parachain/actions/workflows/ci.yml)
[![release](https://github.com/litentry/litentry-parachain/actions/workflows/create-release-draft.yml/badge.svg)](https://github.com/litentry/litentry-parachain/actions/workflows/create-release-draft.yml)
[![runtime upgrade](https://github.com/litentry/litentry-parachain/actions/workflows/check-runtime-upgrade.yml/badge.svg)](https://github.com/litentry/litentry-parachain/actions/workflows/check-runtime-upgrade.yml)
[![general ci](https://github.com/litentry/heima/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/litentry/heima/actions/workflows/ci.yml)
[![release](https://github.com/litentry/heima/actions/workflows/create-release-draft.yml/badge.svg)](https://github.com/litentry/heima/actions/workflows/create-release-draft.yml)
[![runtime upgrade](https://github.com/litentry/heima/actions/workflows/check-runtime-upgrade.yml/badge.svg)](https://github.com/litentry/heima/actions/workflows/check-runtime-upgrade.yml)

</div>

Litentry parachain is a substrate-based, EVM-compatible blockchain that connects to the relaychain (e.g. [Polkadot](https://polkadot.com/)) which ensures shared security and interoperability. It serves as the backbone of Litentry protocol:
- LIT token native features: transfer, governance, staking ...
Being evolved from Litentry, a substrate-based L1 blockchain, **Heima Network** inherits its modularity, flexibility and security, which forms a solid ground for chain abstraction and cross-chain operations. It is also an EVM-compatible blockchain that connects to the relaychain (e.g. [Polkadot](https://polkadot.com/)) which ensures shared security and interoperability, which serves as the backbone of Heima Network:
- HEI token native features: transfer, governance, staking ...
- Runtime logic such as enclave management, DID ...
- parentchain of identity-worker, which is a TEE-based sidechain to achieve identity aggregation and crediential issuance without promising users' privacy
- parentchain of identity-worker, which is a TEE-based sidechain to achieve identity aggregation and crediential issuance without promising users' privacy
- parentchain of bitacross-worker, which is a TEE-based offchain-worker to bridge assets across chains using native custodian and multisig

## Build parachain
Expand Down Expand Up @@ -64,22 +64,22 @@ to stop the processes and tidy things up.
### Launch a standalone parachain node

To speed up the development, the parachain can be launched without relaychain nodes.
In this case, parachain will author blocks by itself with instant block finalisation, please refer to [this PR](https://github.com/litentry/litentry-parachain/pull/1059).
In this case, parachain will author blocks by itself with instant block finalisation, please refer to [this PR](https://github.com/litentry/heima/pull/1059).

```
make launch-standalone
```

## How to build and run tee-worker
## How to build and run identity-worker

### Preparation

- Env: [Setup **SGX TEE** Environment](https://web3builders.notion.site/Setup-SGX-TEE-Environment-68066770831b45b7b632e682cf159477?pvs=4)
- Env: [Setup **SGX TEE** Environment](https://web3builders.notion.site/Setup-SGX-TEE-Environment-68066770831b45b7b632e682cf159477?pvs=4)

### Build

```
cd /tee-worker
cd /tee-worker/identity
source /opt/intel/sgxsdk/environment
SGX_MODE=SW WORKER_DEV=1 make
```
Expand All @@ -91,7 +91,7 @@ Before executing `launch.py`, the following Python libraries need to be installe
pip install python-dotenv pycurl docker toml
```

TEE-workers need a running parachain to become operational. We have an all-in-one script `local-setup/launch.py` to launch both parachain and workers:
Identity-workers need a running parachain to become operational. We have an all-in-one script `local-setup/launch.py` to launch both parachain and workers:
```
./local-setup/launch.py -p standalone
./local-setup/launch.py -p network
Expand All @@ -106,18 +106,18 @@ respectively.

If you see the screenshot below, you can tell the worker is running:

![](https://github.com/cryptoade1/litentry-parachain/assets/88367184/cb1cea60-bc5d-4b62-bae7-503583a135ee)
![](https://github.com/cryptoade1/heima/assets/88367184/cb1cea60-bc5d-4b62-bae7-503583a135ee)

### TEE worker tests
### Identity worker tests

Refer to [tee-worker ts-tests](https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/identity/ts-tests/README.md)
Refer to [identity-worker ts-tests](https://github.com/litentry/heima/blob/dev/tee-worker/identity/ts-tests/README.md)

### Teardown
#### Teardown

In the worker launch terminal, `Ctrl + C` should interrupt and clean everything up automatically.

### Additional Info:
#### Additional Info:

1. Change the RUST_LOG level: `litentry-parachain/local-setup/py/worker.py`
2. Check existing ts-tests: `litentry-parachain/tee-worker/ts-tests/package.json`
3. JSON config parameters: `litentry-parachain/tee-worker/service/src/cli.yml`
1. Change the RUST_LOG level: `local-setup/worker-log-level-config.toml`
2. Check existing ts-tests: `tee-worker/identity/ts-tests/package.json`
3. JSON config parameters: `tee-worker/identity/service/src/cli.yml`
26 changes: 26 additions & 0 deletions parachain/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 parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
'precompiles/collab-ai/guardian',
'precompiles/collab-ai/pool-proposal',
'precompiles/collab-ai/investing-pool',
'precompiles/omni-bridge',
'precompiles/parachain-staking',
'precompiles/score-staking',
'runtime/litentry',
Expand Down Expand Up @@ -293,6 +294,7 @@ pallet-teebag = { path = "pallets/teebag", default-features = false }
pallet-vc-management = { path = "pallets/vc-management", default-features = false }
pallet-evm-precompile-assets-erc20 = { path = "precompiles/assets-erc20", default-features = false }
pallet-evm-precompile-bridge-transfer = { path = "precompiles/bridge-transfer", default-features = false }
pallet-evm-precompile-omni-bridge = { path = "precompiles/omni-bridge", default-features = false }
pallet-evm-precompile-parachain-staking = { path = "precompiles/parachain-staking", default-features = false }
pallet-evm-precompile-score-staking = { path = "precompiles/score-staking", default-features = false }

Expand Down
15 changes: 15 additions & 0 deletions parachain/precompiles/bridge-transfer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry 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.
//
// Litentry 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 Litentry. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]

use fp_evm::{PrecompileFailure, PrecompileHandle};
Expand Down
54 changes: 54 additions & 0 deletions parachain/precompiles/omni-bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[package]
authors = ["Trust Computing GmbH <[email protected]>"]
edition = '2021'
name = "pallet-evm-precompile-omni-bridge"
version = '0.1.0'

[dependencies]
precompile-utils = { workspace = true }

frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-omni-bridge = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

fp-evm = { workspace = true }
pallet-evm = { workspace = true }

core-primitives = { workspace = true }

[dev-dependencies]
derive_more = { workspace = true }
hex-literal = { workspace = true }
libsecp256k1 = { workspace = true, features = ["std"] }
serde = { workspace = true }
sha3 = { workspace = true }
precompile-utils = { workspace = true, features = ["std", "testing"] }
pallet-timestamp = { workspace = true, features = ["std"] }
parity-scale-codec = { workspace = true, features = ["std"] }
sp-runtime = { workspace = true, features = ["std"] }

[features]
default = ["std"]
std = [
"core-primitives/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
"libsecp256k1/std",
"pallet-omni-bridge/std",
"pallet-evm/std",
"pallet-timestamp/std",
"parity-scale-codec/std",
"precompile-utils/std",
"scale-info/std",
"serde/std",
"sha3/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
14 changes: 14 additions & 0 deletions parachain/precompiles/omni-bridge/OmniBridgeInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.3;

interface IOmniBridge {
/// @notice Used to transfer assets through token bridge.
/// @param amount: The amount of tokens to be transferred.
/// @param dest_id: The destination chain id indicator
/// @param native: Indicator of if asset is native. If true, asset_id will be ignored
/// @param asset_id: Resource indicator of type of assets transferred (In substrate runtime it is u128)
/// @param recipient: Recipient address, typically H160/H256
/// @custom:selector 0xef185624
/// payIn(uint256,uint8,bool,uint256,bytes)
function payIn(uint256 amount, uint8 dest_id, bool native, uint256 asset_id, bytes calldata recipient) external;
}
91 changes: 91 additions & 0 deletions parachain/precompiles/omni-bridge/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry 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.
//
// Litentry 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 Litentry. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]

use fp_evm::{PrecompileFailure, PrecompileHandle};

use core_primitives::AssetId;
use frame_support::{
dispatch::{GetDispatchInfo, PostDispatchInfo},
traits::fungible::NativeOrWithId,
};
use pallet_evm::AddressMapping;
use precompile_utils::prelude::*;
use sp_runtime::traits::Dispatchable;

use sp_core::U256;
use sp_std::{marker::PhantomData, vec::Vec};

use pallet_omni_bridge::{ChainType, PayInRequest};

pub struct OmniBridgePrecompile<Runtime>(PhantomData<Runtime>);

type BridgeBalanceOf<Runtime> = <Runtime as pallet_omni_bridge::Config>::Balance;

#[precompile_utils::precompile]
impl<Runtime> OmniBridgePrecompile<Runtime>
where
Runtime: pallet_omni_bridge::Config<AssetKind = NativeOrWithId<AssetId>> + pallet_evm::Config,
Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
Runtime::RuntimeCall: From<pallet_omni_bridge::Call<Runtime>>,
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
BridgeBalanceOf<Runtime>: TryFrom<U256> + Into<U256>,
{
#[precompile::public("payIn(uint256,uint8,bool,uint256,bytes)")]
fn pay_in(
handle: &mut impl PrecompileHandle,
amount: U256,
dest_id: u8,
native: bool,
asset_id: U256,
recipient: UnboundedBytes,
) -> EvmResult {
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);

let amount: BridgeBalanceOf<Runtime> = amount.try_into().map_err(|_| {
Into::<PrecompileFailure>::into(RevertReason::value_is_too_large("balance type"))
})?;
let recipient: Vec<u8> = recipient.into();
let asset_id: AssetId = asset_id.try_into().map_err(|_| {
Into::<PrecompileFailure>::into(RevertReason::value_is_too_large("asset id type"))
})?;

let pay_in_request: PayInRequest<NativeOrWithId<AssetId>, BridgeBalanceOf<Runtime>> =
match native {
true => PayInRequest {
asset: NativeOrWithId::Native,
// This is substrate parachain precompile
// So always be non native chain
dest_chain: ChainType::Ethereum(dest_id.into()),
dest_account: recipient,
amount,
},
false => PayInRequest {
asset: NativeOrWithId::WithId(asset_id),
// This is substrate parachain precompile
// So always be non native chain
dest_chain: ChainType::Ethereum(dest_id.into()),
dest_account: recipient,
amount,
},
};

let call = pallet_omni_bridge::Call::<Runtime>::pay_in { req: pay_in_request };
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
}
}
2 changes: 2 additions & 0 deletions parachain/runtime/litentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }

pallet-evm-precompile-bridge-transfer = { workspace = true }
pallet-evm-precompile-omni-bridge = { workspace = true }
pallet-evm-precompile-parachain-staking = { workspace = true }
pallet-evm-precompile-score-staking = { workspace = true }

Expand Down Expand Up @@ -240,6 +241,7 @@ std = [
"pallet-evm-precompile-blake2/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-bridge-transfer/std",
"pallet-evm-precompile-omni-bridge/std",
"pallet-evm-precompile-dispatch/std",
"pallet-evm-precompile-ed25519/std",
"pallet-evm-precompile-modexp/std",
Expand Down
8 changes: 4 additions & 4 deletions parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("heima"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9230,
spec_version: 9231,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -1008,9 +1008,9 @@ impl pallet_parachain_staking::Config for Runtime {
/// Minimum collators selected per round, default at genesis and minimum forever after
type MinSelectedCandidates = ConstU32<1>;
/// Maximum top delegations per candidate
type MaxTopDelegationsPerCandidate = ConstU32<1000>;
type MaxTopDelegationsPerCandidate = ConstU32<300>;
/// Maximum bottom delegations per candidate
type MaxBottomDelegationsPerCandidate = ConstU32<200>;
type MaxBottomDelegationsPerCandidate = ConstU32<100>;
/// Maximum delegations per delegator
type MaxDelegationsPerDelegator = ConstU32<100>;
type DefaultCollatorCommission = DefaultCollatorCommission;
Expand All @@ -1025,7 +1025,7 @@ impl pallet_parachain_staking::Config for Runtime {
type MinDelegatorStk = MinDelegatorStk;
type OnCollatorPayout = ();
type OnNewRound = ();
type WeightInfo = weights::pallet_parachain_staking::WeightInfo<Runtime>;
type WeightInfo = ();
type IssuanceAdapter = AssetsHandler;
type OnAllDelegationRemoved = ScoreStaking;
}
Expand Down
Loading

0 comments on commit 944defe

Please sign in to comment.