Skip to content

Commit

Permalink
Add zkSBTs (Manta-Network#1012)
Browse files Browse the repository at this point in the history
* init sbt pallet

Signed-off-by: Charles Ferrell <[email protected]>

* update polkadot version for uniques

Signed-off-by: Charles Ferrell <[email protected]>

* fix mock and start tests

Signed-off-by: Charles Ferrell <[email protected]>

* clean up code

Signed-off-by: Charles Ferrell <[email protected]>

* some tests, add checks to_private

Signed-off-by: Charles Ferrell <[email protected]>

* cleanup deps

Signed-off-by: Charles Ferrell <[email protected]>

* fix dependencies

Signed-off-by: Charles Ferrell <[email protected]>

* add pallet sbt to dolphin runtime

Signed-off-by: Charles Ferrell <[email protected]>

* fix rpc

Signed-off-by: Charles Ferrell <[email protected]>

* add reserve sbt

Signed-off-by: Charles Ferrell <[email protected]>

* fix mock

Signed-off-by: Charles Ferrell <[email protected]>

* fmt

Signed-off-by: Charles Ferrell <[email protected]>

* clean up deps

Signed-off-by: Charles Ferrell <[email protected]>

* fix sender ledger to return Ok((()) rather than error

Signed-off-by: Charles Ferrell <[email protected]>

* restructure for some common code

Signed-off-by: Charles Ferrell <[email protected]>

* benchmark sbt

Signed-off-by: Charles Ferrell <[email protected]>

* add weights file

Signed-off-by: Charles Ferrell <[email protected]>

* clean up & tests

Signed-off-by: Charles Ferrell <[email protected]>

* remove duplicate code

Signed-off-by: Charles Ferrell <[email protected]>

* add tests and docs

Signed-off-by: Charles Ferrell <[email protected]>

* fmt

Signed-off-by: Charles Ferrell <[email protected]>

* flip order of event to be more logical

Signed-off-by: Charles Ferrell <[email protected]>

* change AssetMetadata to enum supporting different types of metadata

Signed-off-by: Charles Ferrell <[email protected]>

* update runtimes to new asset manager

Signed-off-by: Charles Ferrell <[email protected]>

* add events to asset manager

Signed-off-by: Charles Ferrell <[email protected]>

* remove uniques

Signed-off-by: Charles Ferrell <[email protected]>

* move storage change to UpdateMetadata trait

Signed-off-by: Charles Ferrell <[email protected]>

* fix Cargo.toml

Signed-off-by: Charles Ferrell <[email protected]>

* fmt Cargo.toml

Signed-off-by: Charles Ferrell <[email protected]>

* fix clippy lints

Signed-off-by: Charles Ferrell <[email protected]>

* fix benchmarking

Signed-off-by: Charles Ferrell <[email protected]>

* add test for asset-manager, add docs and feedback

Signed-off-by: Charles Ferrell <[email protected]>

* tests

Signed-off-by: Charles Ferrell <[email protected]>

* make const and clippy fix

Signed-off-by: Charles Ferrell <[email protected]>

* fix clippy lints

Signed-off-by: Charles Ferrell <[email protected]>

* fmt

Signed-off-by: Charles Ferrell <[email protected]>

* fix benchmark

Signed-off-by: Charles Ferrell <[email protected]>

* fix benchmarking

Signed-off-by: Charles Ferrell <[email protected]>

* better comments and add better errors

Signed-off-by: Charles Ferrell <[email protected]>

* make more functional

Signed-off-by: Charles Ferrell <[email protected]>

* review comment

Signed-off-by: Charles Ferrell <[email protected]>

* remove unnecessary into_iter()

Signed-off-by: Charles Ferrell <[email protected]>

* Better docs

Signed-off-by: Charles Ferrell <[email protected]>

* better name for event

Signed-off-by: Charles Ferrell <[email protected]>

* fix 2022

Signed-off-by: Charles Ferrell <[email protected]>

* change back to use separate storage

Signed-off-by: Charles Ferrell <[email protected]>

* revert asset manager changes

Signed-off-by: Charles Ferrell <[email protected]>

* revert benchmarks too

Signed-off-by: Charles Ferrell <[email protected]>

* cleanup

Signed-off-by: Charles Ferrell <[email protected]>

* more cleanup

Signed-off-by: Charles Ferrell <[email protected]>

* fix error handling

Signed-off-by: Charles Ferrell <[email protected]>

* fix clippy

Signed-off-by: Charles Ferrell <[email protected]>

* update bench and remove unneeded Balance config

Signed-off-by: Charles Ferrell <[email protected]>

* common types and redo weights

Signed-off-by: Charles Ferrell <[email protected]>

* add tests

Signed-off-by: Charles Ferrell <[email protected]>

* fmt

Signed-off-by: Charles Ferrell <[email protected]>

* remove unneeded clones

Signed-off-by: Charles Ferrell <[email protected]>

* remove unneeded pull_senders

Signed-off-by: Charles Ferrell <[email protected]>

* add constant attribute to constants in Config

Signed-off-by: Charles Ferrell <[email protected]>

* docs and make counter start at 1

Signed-off-by: Charles Ferrell <[email protected]>

* fix clippy

Signed-off-by: Charles Ferrell <[email protected]>

* fix benchmarks

Signed-off-by: Charles Ferrell <[email protected]>

* add zkSbt to calamari

Signed-off-by: Charles Ferrell <[email protected]>

* update error handling and add weights file

Signed-off-by: Charles Ferrell <[email protected]>

* make it expensive to mint sbt

Signed-off-by: Charles Ferrell <[email protected]>

* update test

Signed-off-by: zqhxuyuan <[email protected]>

* remove duplicate event

Signed-off-by: zqhxuyuan <[email protected]>

* fix clippy

Signed-off-by: Charles Ferrell <[email protected]>

---------

Signed-off-by: Charles Ferrell <[email protected]>
Signed-off-by: zqhxuyuan <[email protected]>
Co-authored-by: zqhxuyuan <[email protected]>
Co-authored-by: Adam Reif <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2023
1 parent 928dcd7 commit 4aaef92
Show file tree
Hide file tree
Showing 35 changed files with 2,996 additions and 125 deletions.
67 changes: 67 additions & 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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dolphin-runtime = { path = '../runtime/dolphin' }
manta-primitives = { path = '../primitives/manta' }
manta-runtime = { path = '../runtime/manta' }
pallet-manta-pay = { path = '../pallets/manta-pay', features = ["rpc", "runtime"] }
pallet-manta-sbt = { path = '../pallets/manta-sbt', features = ["rpc", "runtime"] }
pallet-parachain-staking = { path = '../pallets/parachain-staking' }
session-key-primitives = { path = '../primitives/session-keys' }

Expand Down
2 changes: 1 addition & 1 deletion node/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2022 Manta Network.
// Copyright 2020-2023 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion node/src/instant_finalize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2022 Manta Network.
// Copyright 2020-2023 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
Expand Down
12 changes: 11 additions & 1 deletion node/src/rpc/calamari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use pallet_manta_pay::{
rpc::{Pull, PullApiServer},
runtime::PullLedgerDiffApi,
};
use pallet_manta_sbt::{
rpc::{SBTPull, SBTPullApiServer},
runtime::SBTPullLedgerDiffApi,
};

/// Instantiate all RPC extensions for calamari.
pub fn create_calamari_full<C, P>(deps: FullDeps<C, P>) -> Result<RpcExtension, sc_service::Error>
Expand All @@ -36,6 +40,7 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
C::Api: PullLedgerDiffApi<Block>,
C::Api: SBTPullLedgerDiffApi<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{System, SystemApiServer};
Expand All @@ -55,10 +60,15 @@ where
.merge(TransactionPayment::new(client.clone()).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

let manta_pay_rpc: jsonrpsee::RpcModule<Pull<Block, C>> = Pull::new(client).into_rpc();
let manta_pay_rpc: jsonrpsee::RpcModule<Pull<Block, C>> = Pull::new(client.clone()).into_rpc();
module
.merge(manta_pay_rpc)
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

let manta_sbt_rpc: jsonrpsee::RpcModule<SBTPull<Block, C>> = SBTPull::new(client).into_rpc();
module
.merge(manta_sbt_rpc)
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

Ok(module)
}
12 changes: 11 additions & 1 deletion node/src/rpc/dolphin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use pallet_manta_pay::{
rpc::{Pull, PullApiServer},
runtime::PullLedgerDiffApi,
};
use pallet_manta_sbt::{
rpc::{SBTPull, SBTPullApiServer},
runtime::SBTPullLedgerDiffApi,
};

/// Instantiate all RPC extensions for dolphin.
pub fn create_dolphin_full<C, P>(deps: FullDeps<C, P>) -> Result<RpcExtension, sc_service::Error>
Expand All @@ -36,6 +40,7 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
C::Api: PullLedgerDiffApi<Block>,
C::Api: SBTPullLedgerDiffApi<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{System, SystemApiServer};
Expand All @@ -55,10 +60,15 @@ where
.merge(TransactionPayment::new(client.clone()).into_rpc())
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

let manta_pay_rpc: jsonrpsee::RpcModule<Pull<Block, C>> = Pull::new(client).into_rpc();
let manta_pay_rpc: jsonrpsee::RpcModule<Pull<Block, C>> = Pull::new(client.clone()).into_rpc();
module
.merge(manta_pay_rpc)
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

let manta_sbt_rpc: jsonrpsee::RpcModule<SBTPull<Block, C>> = SBTPull::new(client).into_rpc();
module
.merge(manta_sbt_rpc)
.map_err(|e| sc_service::Error::Other(e.to_string()))?;

Ok(module)
}
7 changes: 4 additions & 3 deletions pallets/manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rpc = [
"serde",
"sp-api",
"sp-blockchain",
"manta-support/rpc",
]

# Runtime API
Expand All @@ -45,9 +46,7 @@ runtime-benchmarks = [

# Serde Serialization
serde = [
"manta-pay/serde",
"manta-util/serde",
"manta-util/serde_with",
"manta-support/serde",
]

# Standard Library
Expand All @@ -66,6 +65,7 @@ std = [
"manta-crypto/std",
"manta-util/std",
"manta-pay/std",
"manta-support/std",
]

# Precompute Benchmark Transactions
Expand Down Expand Up @@ -111,6 +111,7 @@ manta-accounting = { git = "https://github.com/manta-network/manta-rs.git", tag
manta-crypto = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.12", default-features = false }
manta-pay = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.12", default-features = false, features = ["groth16", "parameters", "scale"] }
manta-primitives = { path = "../../primitives/manta", default-features = false }
manta-support = { package = "pallet-manta-support", path = "../manta-support", default-features = false }
manta-util = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.12", default-features = false }

[dev-dependencies]
Expand Down
8 changes: 5 additions & 3 deletions pallets/manta-pay/src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ use crate::{
benchmark::precomputed_coins::{
PRIVATE_TRANSFER, PRIVATE_TRANSFER_INPUT, TO_PRIVATE, TO_PUBLIC, TO_PUBLIC_INPUT,
},
types::{asset_value_decode, asset_value_encode, AccountId, Asset},
Call, Config, Event, Pallet, StandardAssetId, TransferPost,
};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::traits::Get;
use frame_system::RawOrigin;
use manta_support::manta_pay::{
asset_value_decode, asset_value_encode, field_from_id, id_from_field, AccountId, Asset,
};

use manta_primitives::{
assets::{AssetConfig, AssetRegistry, FungibleLedger, TestingDefault},
Expand Down Expand Up @@ -85,7 +87,7 @@ benchmarks! {
let origin = T::Origin::from(RawOrigin::Signed(caller.clone()));
let mint_post = TransferPost::decode(&mut &*TO_PRIVATE).unwrap();
let asset = mint_post.source(0).unwrap();
init_asset::<T>(&caller, Pallet::<T>::id_from_field(asset.id).unwrap(), asset_value_decode(asset.value));
init_asset::<T>(&caller, id_from_field(asset.id).unwrap(), asset_value_decode(asset.value));
}: to_private (
RawOrigin::Signed(caller.clone()),
mint_post
Expand Down Expand Up @@ -136,7 +138,7 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
let origin = T::Origin::from(RawOrigin::Signed(caller.clone()));
init_asset::<T>(&caller, <T::AssetConfig as AssetConfig<T>>::StartNonNativeAssetId::get(), INITIAL_VALUE);
let asset = Asset::new(Pallet::<T>::field_from_id(8u128), asset_value_encode(100));
let asset = Asset::new(field_from_id(8u128), asset_value_encode(100));
let sink = Pallet::<T>::account_id();
}: public_transfer (
RawOrigin::Signed(caller.clone()),
Expand Down
2 changes: 1 addition & 1 deletion pallets/manta-pay/src/bin/precompute_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use manta_pay::{
parameters::load_parameters,
test,
};
use pallet_manta_pay::types::{AccountId, TransferPost};
use manta_support::manta_pay::{AccountId, TransferPost};
use rand_chacha::ChaCha20Rng;
use scale_codec::Encode;
use std::{
Expand Down
18 changes: 0 additions & 18 deletions pallets/manta-pay/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ where
}
}

/// Merkle Tree Parameters Decode Error Type
pub type MTParametersError = codec::DecodeError<
<&'static [u8] as codec::Read>::Error,
<config::UtxoAccumulatorModel as codec::Decode>::Error,
>;

/// Utxo Accumulator Item Hash Decode Error Type
pub type UtxoItemHashError = codec::DecodeError<
<&'static [u8] as codec::Read>::Error,
<config::utxo::UtxoAccumulatorItemHash as codec::Decode>::Error,
>;

/// Verification Context Decode Error Type
pub type VerifyingContextError = codec::DecodeError<
<&'static [u8] as codec::Read>::Error,
<config::VerifyingContext as codec::Decode>::Error,
>;

/// Receiver Ledger Error
pub enum ReceiverLedgerError<T>
where
Expand Down
Loading

0 comments on commit 4aaef92

Please sign in to comment.