Skip to content

Commit

Permalink
ZKSaaS pallet (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex authored Dec 8, 2023
1 parent 9c0589b commit 7e33732
Show file tree
Hide file tree
Showing 35 changed files with 2,318 additions and 680 deletions.
799 changes: 543 additions & 256 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ members = [
"runtime/testnet/evm_tracer",
"runtime/mainnet",
"pallets/*",
"pallets/claims",
"pallets/roles",
"pallets/jobs/rpc",
"pallets/jobs/rpc/runtime-api",
"precompiles/utils",
Expand Down Expand Up @@ -71,7 +69,7 @@ syn = { version = "1.0" }
hex = { version = "0.4.3", default-features = false }
paste = "1.0.6"
slices = "0.2.0"
schnorrkel = { verison = "11.4", default-features = false }
schnorrkel = { version = "0.9.1", default-features = false }

# DKG Substrate Dependencies
dkg-runtime-primitives = { git = "https://github.com/webb-tools/dkg-substrate.git", tag = "v0.4.7", default-features = false }
Expand All @@ -87,6 +85,22 @@ webb-relayer-gadget-cli = { git = "https://github.com/webb-tools/dkg-substrate.g
tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
tangle-mainnet-runtime = { package = "tangle-mainnet-runtime", path = "runtime/mainnet" }

# Arkworks
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-relations = { version = "^0.4.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false, features = ["derive"] }
ark-std = { version = "^0.4.0", default-features = false }
ark-groth16 = { version = "0.4.0", default-features = false }

# Ark Curves
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] }

ark-crypto-primitives = { version = "^0.4.0", default-features = false }

ethabi = { version = "15.0.0", default-features = false }

# Tangle Dependencies
pallet-airdrop-claims = { path = "pallets/claims", default-features = false }
pallet-jobs = { path = "pallets/jobs", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/txpool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sha3::{Digest, Keccak256};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_runtime::traits::Block as BlockT;
use std::{collections::HashMap, marker::PhantomData, sync::Arc};
use std::{marker::PhantomData, sync::Arc};

use rpc_primitives_txpool::{Transaction as TransactionV2, TxPoolResponse, TxPoolRuntimeApi};

Expand Down Expand Up @@ -106,7 +106,7 @@ where
};
pending
.entry(from_address)
.or_insert_with(HashMap::new)
.or_default()
.insert(nonce, T::get(hash, from_address, txn));
}
let mut queued = TransactionMap::<T>::new();
Expand All @@ -123,7 +123,7 @@ where
};
queued
.entry(from_address)
.or_insert_with(HashMap::new)
.or_default()
.insert(nonce, T::get(hash, from_address, txn));
}
Ok(TxPoolResult { pending, queued })
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

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

4 changes: 2 additions & 2 deletions pallets/dkg/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl<T: Config> Pallet<T> {
/// an error.
pub fn verify(data: JobResult) -> DispatchResult {
match data {
JobResult::DKG(info) => Self::verify_generated_dkg_key(info),
JobResult::DKGSignature(info) => Self::verify_dkg_signature(info),
JobResult::DKGPhaseOne(info) => Self::verify_generated_dkg_key(info),
JobResult::DKGPhaseTwo(info) => Self::verify_dkg_signature(info),
_ => Err(Error::<T>::InvalidJobType.into()), // this should never happen
}
}
Expand Down
16 changes: 8 additions & 8 deletions pallets/dkg/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn dkg_key_verifcation_works() {

// should fail for empty participants
assert_noop!(
DKG::verify(JobResult::DKG(job_to_verify)),
DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),
Error::<Runtime>::NoParticipantsFound
);

Expand All @@ -79,7 +79,7 @@ fn dkg_key_verifcation_works() {

// should fail for empty keys/signatures
assert_noop!(
DKG::verify(JobResult::DKG(job_to_verify)),
DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),
Error::<Runtime>::NoSignaturesFound
);

Expand All @@ -96,7 +96,7 @@ fn dkg_key_verifcation_works() {

// should fail for less than threshold
assert_noop!(
DKG::verify(JobResult::DKG(job_to_verify)),
DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),
Error::<Runtime>::NotEnoughSigners
);

Expand All @@ -109,7 +109,7 @@ fn dkg_key_verifcation_works() {

// should fail for duplicate signers
assert_noop!(
DKG::verify(JobResult::DKG(job_to_verify)),
DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),
Error::<Runtime>::DuplicateSignature
);

Expand All @@ -122,7 +122,7 @@ fn dkg_key_verifcation_works() {

// should fail for signing different keys
assert_noop!(
DKG::verify(JobResult::DKG(job_to_verify)),
DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),
Error::<Runtime>::InvalidSignatureData
);

Expand All @@ -139,7 +139,7 @@ fn dkg_key_verifcation_works() {
};

// should fail for signing different keys
assert_ok!(DKG::verify(JobResult::DKG(job_to_verify)),);
assert_ok!(DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),);
});
}

Expand All @@ -158,7 +158,7 @@ fn dkg_signature_verifcation_works() {

// should fail for invalid keys
assert_noop!(
DKG::verify(JobResult::DKGSignature(job_to_verify)),
DKG::verify(JobResult::DKGPhaseTwo(job_to_verify)),
Error::<Runtime>::SigningKeyMismatch
);

Expand All @@ -170,6 +170,6 @@ fn dkg_signature_verifcation_works() {
};

// should work with correct params
assert_ok!(DKG::verify(JobResult::DKGSignature(job_to_verify)));
assert_ok!(DKG::verify(JobResult::DKGPhaseTwo(job_to_verify)));
});
}
Loading

0 comments on commit 7e33732

Please sign in to comment.