Skip to content

Commit

Permalink
ZkSaaS gadget code in-place
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex committed Dec 18, 2023
1 parent 9eb29d6 commit c813a07
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 147 deletions.
59 changes: 26 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,48 @@ gadget-common = { path = "./gadget-common" }
zk-gadget = { path = "./zk-gadget" }
mp-ecdsa-protocol = { path = "./protocols/mp-ecdsa" }

pallet-jobs-rpc-runtime-api = { git = "https://github.com/webb-tools/tangle" }
tangle-primitives = { git = "https://github.com/webb-tools/tangle" }
tangle-testnet-runtime = { git = "https://github.com/webb-tools/tangle" }
tangle-mainnet-runtime = { git = "https://github.com/webb-tools/tangle" }
pallet-jobs-rpc-runtime-api = { git = "https://github.com/webb-tools/tangle", default-features = false }
tangle-primitives = { git = "https://github.com/webb-tools/tangle", default-features = false }
tangle-testnet-runtime = { git = "https://github.com/webb-tools/tangle", default-features = false }
tangle-mainnet-runtime = { git = "https://github.com/webb-tools/tangle", default-features = false }

multi-party-ecdsa = { git = "https://github.com/webb-tools/cggmp-threshold-ecdsa/" }
round-based = { git = "https://github.com/webb-tools/round-based-protocol", features = [] }
curv = { package = "curv-kzen", version = "0.10.0" }

sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-application-crypto = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sc-utils = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sp-application-crypto = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }

sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-network = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-network-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-rpc-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
parity-scale-codec = "3.6.5"

substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
pallet-im-online = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }

mpc-net = { git = "https://github.com/webb-tools/zk-SaaS/" }
dist-primitives = { git = "https://github.com/webb-tools/zk-SaaS/" }
secret-sharing = { git = "https://github.com/webb-tools/zk-SaaS/" }
groth16 = { git = "https://github.com/webb-tools/zk-SaaS/" }

tokio-rustls = "0.24.1"
# ARK Libraries
ark-std = { version = "0.4.0", default-features = false, features = [ "print-trace", "std" ] }
ark-crypto-primitives = { version = "0.4.0", default-features = false }
ark-ff = { version = "0.4.2", default-features = false }
ark-poly = { version = "0.4.2", default-features = false }
ark-ec = { version = "0.4.2", default-features = false }
ark-relations = { version = "0.4.0", default-features = false }
ark-serialize = { version = "0.4.2", default-features = false, features = [ "derive" ] }
ark-groth16 = { version = "0.4.0", default-features = false }
ark-circom = { git = "https://github.com/webb-tools/ark-circom.git" }
# ARK curves
ark-bn254 = { version = "0.4.0", default-features = false, features = ["curve"] }

tokio-rustls = "0.24"
tokio = "1.32.0"
bincode2 = "2"
futures-util = "0.3.28"
Expand All @@ -81,4 +74,4 @@ clap = "4.0.32"
hex-literal = "0.4.1"
rand = "0.8.5"
jsonrpsee = "0.16.2"
linked-hash-map = "0.5.6"
linked-hash-map = "0.5.6"
13 changes: 3 additions & 10 deletions gadget-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = [
"std"
]

std = [
"sp-api/std",
"tangle-primitives/std",
"pallet-jobs-rpc-runtime-api/std"
]
default = ["std"]
std = []

[dependencies]
gadget-core = { workspace = true, features = ["substrate"] }
Expand All @@ -32,4 +25,4 @@ bincode2 = { workspace = true }

sp-api = { workspace = true, default-features = false }
tangle-primitives = { workspace = true, default-features = false }
pallet-jobs-rpc-runtime-api = { workspace = true, default-features = false }
pallet-jobs-rpc-runtime-api = { workspace = true, default-features = false }
4 changes: 2 additions & 2 deletions gadget-common/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use crate::debug_logger::DebugLogger;
use crate::keystore::{ECDSAKeyStore, KeystoreBackend};
use async_trait::async_trait;
use gadget_core::gadget::substrate::Client;
use pallet_jobs_rpc_runtime_api::{JobsApi, RpcResponseJobsData};
use pallet_jobs_rpc_runtime_api::JobsApi;
use sc_client_api::{
Backend, BlockImportNotification, BlockchainEvents, FinalityNotification, HeaderBackend,
};
use sp_api::BlockT as Block;
use sp_api::ProvideRuntimeApi;
use std::error::Error;
use std::sync::Arc;
use tangle_primitives::jobs::{JobId, JobKey, JobResult};
use tangle_primitives::jobs::{JobId, JobKey, JobResult, RpcResponseJobsData};

pub struct MpEcdsaClient<B: Block, BE, KBE: KeystoreBackend, C> {
client: Arc<C>,
Expand Down
6 changes: 3 additions & 3 deletions gadget-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"

[features]
substrate = [
"sp-runtime",
"sc-client-api",
"sp-runtime",
"sc-client-api",
]

[dependencies]
Expand All @@ -23,4 +23,4 @@ sp-runtime = { optional = true, workspace = true }
sc-client-api = { optional = true, workspace = true }

[dev-dependencies]
tokio = { workspace = true, features = ["macros"]}
tokio = { workspace = true, features = ["macros"] }
15 changes: 7 additions & 8 deletions protocols/mp-ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ itertools = { workspace = true }
bincode2 = { workspace = true }
linked-hash-map = { workspace = true }

pallet-jobs-rpc-runtime-api = { workspace = true, features = ["std"] }
tangle-primitives = { workspace = true, features = ["std"] }

sp-core = { workspace = true, features = ["std"] }
sp-api = { workspace = true, features = ["std"] }
sp-runtime = { workspace = true, features = ["std"] }
sp-application-crypto = { workspace = true, features = ["std"] }
sp-consensus-aura = { workspace = true, features = ["std"] }
pallet-jobs-rpc-runtime-api = { workspace = true, default-features = false, features = ["std"] }
tangle-primitives = { workspace = true, default-features = false }

sp-core = { workspace = true }
sp-api = { workspace = true }
sp-runtime = { workspace = true }
sp-application-crypto = { workspace = true }

sc-client-api = { workspace = true }
sc-network = { workspace = true }
Expand Down
24 changes: 19 additions & 5 deletions zk-gadget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ edition = "2021"
[dependencies]
tokio-rustls = { workspace = true }
mpc-net = { workspace = true }
secret-sharing = { workspace = true }
dist-primitives = { workspace = true }
groth16 = { workspace = true }
gadget-common = { workspace = true }
gadget-core = { workspace = true }
bincode2 = { workspace = true }
Expand All @@ -19,22 +22,33 @@ async-trait = { workspace = true }
parking_lot = { workspace = true }
log = { workspace = true }
bytes = { workspace = true, features = ["serde"] }
sp-runtime = { workspace = true }
fflonk = { git = "https://github.com/w3f/fflonk", features = ["std"] }


sp-runtime = { workspace = true }
sp-core = { workspace = true }
sp-api = { workspace = true }

pallet-jobs-rpc-runtime-api = { workspace = true }
tangle-primitives = { workspace = true }
tangle-primitives = { workspace = true, features = ["verifying"] }

ark-serialize = { workspace = true, default-features = false }
ark-groth16 = { workspace = true, default-features = false }
ark-poly = { workspace = true, default-features = false }
ark-relations = { workspace = true, default-features = false }
ark-ec = { workspace = true, default-features = false }
ark-crypto-primitives = { workspace = true, default-features = false }
ark-ff = { workspace = true, default-features = false }
ark-circom = { workspace = true }

sp-core = { workspace = true }
sp-api = { workspace = true }

ark-bn254 = { workspace = true, default-features = false, features = ["curve"] }

[dev-dependencies]
sp-runtime = { workspace = true }
sc-utils = { workspace = true }
sc-client-api = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
rcgen = "0.11.3"
rcgen = "0.12"
parity-scale-codec = { workspace = true, features = ["derive"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
22 changes: 6 additions & 16 deletions zk-gadget/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::client_ext::ClientWithApi;
use crate::network::ZkNetworkService;
use crate::protocol::{AdditionalProtocolParams, ZkProtocol};
use crate::protocol::ZkProtocol;
use client_ext::AccountId;
use gadget_common::Error;
use mpc_net::prod::RustlsCertificate;
use pallet_jobs_rpc_runtime_api::JobsApi;
use sp_api::ProvideRuntimeApi;
use sp_core::ecdsa;
use sp_runtime::traits::Block;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio_rustls::rustls::{Certificate, PrivateKey, RootCertStore};

pub mod network;
Expand All @@ -23,23 +23,12 @@ pub struct ZkGadgetConfig {
pub public_identity_der: Vec<u8>,
pub private_identity_der: Vec<u8>,
pub client_only_king_public_identity_der: Option<Vec<u8>>,
pub account_id: AccountId,
}

pub struct ZkSaaSConfig {}

pub async fn run<B, C>(config: ZkSaaSConfig, client: C) -> Result<(), Error>
where
B: Block,
C: ClientWithApi<B>,
<C as ProvideRuntimeApi<B>>::Api: JobsApi<B, ecdsa::Public>,
{
let client = Arc::new(client);
}

pub async fn run_zk_saas<C: ClientWithApi<B>, B: Block, T: AdditionalProtocolParams>(
pub async fn run<C: ClientWithApi<B> + 'static, B: Block>(
config: ZkGadgetConfig,
client: C,
extra_parameters: T,
) -> Result<(), Error>
where
<C as ProvideRuntimeApi<B>>::Api: JobsApi<B, ecdsa::Public>,
Expand All @@ -49,9 +38,9 @@ where
log::info!("Created zk network for party {}", config.network_id);

let zk_protocol = ZkProtocol {
additional_params: extra_parameters,
client: client.clone(),
_pd: std::marker::PhantomData,
account_id: config.account_id,
network: network.clone(),
};

Expand All @@ -64,6 +53,7 @@ pub async fn create_zk_network(config: &ZkGadgetConfig) -> Result<ZkNetworkServi
cert: Certificate(config.public_identity_der.clone()),
private_key: PrivateKey(config.private_identity_der.clone()),
};

if let Some(addr) = &config.king_bind_addr {
ZkNetworkService::new_king(config.network_id, *addr, our_identity).await
} else {
Expand Down
4 changes: 2 additions & 2 deletions zk-gadget/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pub enum ZkNetworkService {
},
}

struct ClientRegistryResult {
pub struct ClientRegistryResult {
tx: Option<tokio::sync::oneshot::Sender<HashMap<u32, RegistantId>>>,
rx: Option<tokio::sync::oneshot::Receiver<HashMap<u32, RegistantId>>>,
}

struct KingRegistryResult {
pub struct KingRegistryResult {
tx: Option<UnboundedSender<ZkSetupPacket>>,
rx: Option<UnboundedReceiver<ZkSetupPacket>>,
}
Expand Down
Loading

0 comments on commit c813a07

Please sign in to comment.