Skip to content

Commit

Permalink
Merge branch 'main' into salman/add-pallet-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
salman01zp authored Dec 19, 2023
2 parents fab3c1f + 3f656b4 commit 8c5622e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pallet-airdrop-claims = { path = "pallets/claims", default-features = false }
pallet-jobs = { path = "pallets/jobs", default-features = false }
pallet-roles = { path = "pallets/roles", default-features = false }
pallet-dkg = { path = "pallets/dkg", default-features = false }
pallet-zksaas = { path = "pallets/zksaas", default-features = false }

# Substrate dependencies
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
Expand Down
8 changes: 7 additions & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ hex = { workspace = true }

[features]
default = ["std", "verifying"]
std = ["frame-support/std", "sp-runtime/std", "sp-core/std", "sp-consensus-aura/std"]
std = [
"frame-support/std",
"sp-runtime/std",
"sp-core/std",
"sp-consensus-aura/std",
"ark-std?/std",
]
verifying = [
"ark-crypto-primitives",
"ark-ec",
Expand Down
21 changes: 19 additions & 2 deletions primitives/src/verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ark_crypto_primitives::Error;
use ark_ff::{BigInteger, PrimeField};
use sp_std::vec::Vec;

pub mod arkworks;
pub mod circom;
Expand Down Expand Up @@ -31,19 +32,35 @@ pub fn to_field_elements<F: PrimeField>(bytes: &[u8]) -> Result<Vec<F>, Error> {

/// Convert a vector of field elements into a vector of bytes.
pub fn from_field_elements<F: PrimeField>(elts: &[F]) -> Result<Vec<u8>, Error> {
let res = elts.iter().fold(vec![], |mut acc, prev| {
let res = elts.iter().fold(Vec::with_capacity(elts.len() * 32), |mut acc, prev| {
acc.extend_from_slice(&prev.into_bigint().to_bytes_be());
acc
});

Ok(res)
}

// A trait meant to be implemented over a zero-knowledge verifier function.
/// A trait meant to be implemented over a zero-knowledge verifier function.
pub trait InstanceVerifier {
fn verify(pub_inps: &[u8], proof: &[u8], params: &[u8]) -> Result<bool, Error>;
}

/// A verifier that always returns true.
#[derive(Clone, Copy, Debug)]
pub struct PassThroughVerifier;

impl InstanceVerifier for PassThroughVerifier {
fn verify(_pub_inps: &[u8], _proof: &[u8], _params: &[u8]) -> Result<bool, Error> {
Ok(true)
}
}

impl InstanceVerifier for () {
fn verify(_pub_inps: &[u8], _proof: &[u8], _params: &[u8]) -> Result<bool, Error> {
Ok(false)
}
}

impl<V1, V2> InstanceVerifier for (V1, V2)
where
V1: InstanceVerifier,
Expand Down
4 changes: 3 additions & 1 deletion runtime/testnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ pallet-vesting = { workspace = true }

# Webb dependencies
pallet-dkg = { workspace = true }
pallet-zksaas = { workspace = true }
pallet-jobs = { workspace = true }
pallet-roles = { workspace = true }
tangle-primitives = { workspace = true }
tangle-primitives = { workspace = true, features = ["verifying"] }

# Frontier dependencies
fp-account = { workspace = true }
Expand Down Expand Up @@ -209,6 +210,7 @@ std = [
"pallet-jobs/std",
"pallet-roles/std",
"pallet-dkg/std",
"pallet-zksaas/std",

# ETH2 light-client
"pallet-eth2-light-client/std",
Expand Down
20 changes: 15 additions & 5 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use tangle_primitives::{
jobs::{JobResult, JobSubmission, JobType, JobWithResult, ValidatorOffenceType},
roles::ValidatorRewardDistribution,
traits::jobs::{JobToFee, MPCHandler},
verifier::{arkworks::ArkworksVerifierGroth16Bn254, circom::CircomVerifierGroth16Bn254},
};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -1098,8 +1099,8 @@ impl JobToFee<AccountId, BlockNumber> for MockJobToFeeHandler {
match job.job_type {
JobType::DKGTSSPhaseOne(_) => Dkg::job_to_fee(job),
JobType::DKGTSSPhaseTwo(_) => Dkg::job_to_fee(job),
JobType::ZkSaaSPhaseOne(_) => todo!(), // TODO : Replace with zksaas pallet
JobType::ZkSaaSPhaseTwo(_) => todo!(), // TODO : Replace with zksaas pallet
JobType::ZkSaaSPhaseOne(_) => ZkSaaS::job_to_fee(job),
JobType::ZkSaaSPhaseTwo(_) => ZkSaaS::job_to_fee(job),
}
}
}
Expand All @@ -1111,8 +1112,8 @@ impl MPCHandler<AccountId, BlockNumber, Balance> for MockMPCHandler {
match data.result {
JobResult::DKGPhaseOne(_) => Dkg::verify(data.result),
JobResult::DKGPhaseTwo(_) => Dkg::verify(data.result),
JobResult::ZkSaaSPhaseOne(_) => todo!(), // TODO : Replace with zksaas pallet
JobResult::ZkSaaSPhaseTwo(_) => todo!(), // TODO : Replace with zksaas pallet
JobResult::ZkSaaSPhaseOne(_) => ZkSaaS::verify(data),
JobResult::ZkSaaSPhaseTwo(_) => ZkSaaS::verify(data),
}
}

Expand Down Expand Up @@ -1179,6 +1180,14 @@ impl pallet_dkg::Config for Runtime {
type WeightInfo = ();
}

impl pallet_zksaas::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type UpdateOrigin = EnsureRootOrHalfCouncil;
type Verifier = (ArkworksVerifierGroth16Bn254, CircomVerifierGroth16Bn254);
type WeightInfo = ();
}

pub struct BaseFilter;
impl Contains<RuntimeCall> for BaseFilter {
fn contains(call: &RuntimeCall) -> bool {
Expand Down Expand Up @@ -1264,7 +1273,8 @@ construct_runtime!(

Roles: pallet_roles,
Jobs: pallet_jobs,
Dkg: pallet_dkg
Dkg: pallet_dkg,
ZkSaaS: pallet_zksaas,
}
);

Expand Down

0 comments on commit 8c5622e

Please sign in to comment.