Skip to content

Commit

Permalink
Add Evm Allowlist Feature to SBT Pallet (#1057)
Browse files Browse the repository at this point in the history
* init sbt pallet

Signed-off-by: Charles Ferrell <charlie@manta.network>

* update polkadot version for uniques

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix mock and start tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* clean up code

Signed-off-by: Charles Ferrell <charlie@manta.network>

* some tests, add checks to_private

Signed-off-by: Charles Ferrell <charlie@manta.network>

* cleanup deps

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix dependencies

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add pallet sbt to dolphin runtime

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix rpc

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add reserve sbt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix mock

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* clean up deps

Signed-off-by: Charles Ferrell <charlie@manta.network>

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

Signed-off-by: Charles Ferrell <charlie@manta.network>

* restructure for some common code

Signed-off-by: Charles Ferrell <charlie@manta.network>

* benchmark sbt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add weights file

Signed-off-by: Charles Ferrell <charlie@manta.network>

* clean up & tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* remove duplicate code

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add tests and docs

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* flip order of event to be more logical

Signed-off-by: Charles Ferrell <charlie@manta.network>

* change AssetMetadata to enum supporting different types of metadata

Signed-off-by: Charles Ferrell <charlie@manta.network>

* update runtimes to new asset manager

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add events to asset manager

Signed-off-by: Charles Ferrell <charlie@manta.network>

* remove uniques

Signed-off-by: Charles Ferrell <charlie@manta.network>

* move storage change to UpdateMetadata trait

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix Cargo.toml

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt Cargo.toml

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix clippy lints

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix benchmarking

Signed-off-by: Charles Ferrell <charlie@manta.network>

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

Signed-off-by: Charles Ferrell <charlie@manta.network>

* tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* make const and clippy fix

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix clippy lints

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix benchmark

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix benchmarking

Signed-off-by: Charles Ferrell <charlie@manta.network>

* better comments and add better errors

Signed-off-by: Charles Ferrell <charlie@manta.network>

* make more functional

Signed-off-by: Charles Ferrell <charlie@manta.network>

* review comment

Signed-off-by: Charles Ferrell <charlie@manta.network>

* remove unnecessary into_iter()

Signed-off-by: Charles Ferrell <charlie@manta.network>

* Better docs

Signed-off-by: Charles Ferrell <charlie@manta.network>

* better name for event

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix 2022

Signed-off-by: Charles Ferrell <charlie@manta.network>

* change back to use separate storage

Signed-off-by: Charles Ferrell <charlie@manta.network>

* revert asset manager changes

Signed-off-by: Charles Ferrell <charlie@manta.network>

* revert benchmarks too

Signed-off-by: Charles Ferrell <charlie@manta.network>

* cleanup

Signed-off-by: Charles Ferrell <charlie@manta.network>

* more cleanup

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix error handling

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix clippy

Signed-off-by: Charles Ferrell <charlie@manta.network>

* update bench and remove unneeded Balance config

Signed-off-by: Charles Ferrell <charlie@manta.network>

* common types and redo weights

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* remove unneeded clones

Signed-off-by: Charles Ferrell <charlie@manta.network>

* remove unneeded pull_senders

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add constant attribute to constants in Config

Signed-off-by: Charles Ferrell <charlie@manta.network>

* docs and make counter start at 1

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix clippy

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix benchmarks

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add zkSbt to calamari

Signed-off-by: Charles Ferrell <charlie@manta.network>

* update error handling and add weights file

Signed-off-by: Charles Ferrell <charlie@manta.network>

* make it expensive to mint sbt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* initial evm sbt implementation

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add to runtime and add whitelist account to storage

Signed-off-by: Charles Ferrell <charlie@manta.network>

* Add metadata to minting

Signed-off-by: Charles Ferrell <charlie@manta.network>

* after minting remove account from whitelist

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add enum types and change signature to use proof field

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix version and more tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add timestamp logic

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add eth mint and timestamp tests

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add to tests some more

Signed-off-by: Charles Ferrell <charlie@manta.network>

* change whiteist to allowlist

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add benchmarks

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add weights for new calls

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add and fix docs

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix docs

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fix typos

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add AlreadyMinted Error

Signed-off-by: Charles Ferrell <charlie@manta.network>

* update unit test

Signed-off-by: Charles Ferrell <charlie@manta.network>

* decouple from pallet_timestamp

Signed-off-by: Charles Ferrell <charlie@manta.network>

* fmt

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add check for valid time range

Signed-off-by: Charles Ferrell <charlie@manta.network>

* add metadata

Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>

* metadata optional

Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>

* add chain_id config

Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>

* rename time range to mint info

Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>

* make storage bounded

Signed-off-by: Charles Ferrell <charlie@manta.network>

* MintChainInfo generic and add docs

Signed-off-by: Charles Ferrell <charlie@manta.network>

* 2/3 tech commitee and add comments

Signed-off-by: Charles Ferrell <charlie@manta.network>

---------

Signed-off-by: Charles Ferrell <charlie@manta.network>
Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>
Co-authored-by: zqhxuyuan <zqhxuyuan@gmail.com>
  • Loading branch information
ferrell-code and zqhxuyuan authored Apr 5, 2023
1 parent c9bf02f commit eb538c3
Show file tree
Hide file tree
Showing 12 changed files with 1,047 additions and 81 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock

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

14 changes: 11 additions & 3 deletions pallets/manta-sbt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = 'GPL-3.0'
name = 'pallet-manta-sbt'
readme = 'README.md'
repository = 'https://github.com/Manta-Network/Manta/'
version = '4.0.2'
version = '4.0.4'

[[bin]]
name = "precompute_coins"
Expand All @@ -20,6 +20,7 @@ default = ["std"]
# Runtime Benchmarks
runtime-benchmarks = [
"frame-benchmarking",
"libsecp256k1/hmac",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"manta-primitives/runtime-benchmarks",
Expand All @@ -28,6 +29,8 @@ runtime-benchmarks = [
# Standard Library
std = [
"anyhow/std",
"sha3/std",
"libsecp256k1/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
Expand All @@ -36,6 +39,8 @@ std = [
"sp-runtime/std",
"sp-api/std",
"sp-std/std",
"sp-core/std",
"sp-io/std",
"manta-primitives/std",
"manta-accounting/std",
"manta-crypto/std",
Expand Down Expand Up @@ -83,7 +88,9 @@ precompute-coins = [
anyhow = { version = "1.0.55", optional = true, default-features = false }
base64 = { version = "0.20", default-features = false, features = ["alloc"] }
indoc = { version = "1.0.3", optional = true, default-features = false }
libsecp256k1 = { version = "0.7", default-features = false, features = ["hmac", "static-context"], optional = true }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
sha3 = { version = "0.10.6", default-features = false }
tempfile = { version = "3.3.0", optional = true, default-features = false }

# substrate dependencies
Expand All @@ -94,6 +101,8 @@ scale-codec = { package = "parity-scale-codec", version = '3.1.2', default-featu
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28", optional = true, default-features = false }
sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28", optional = true, default-features = false }
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28", default-features = false }
sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features = false }
sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28", default-features = false }

Expand All @@ -116,8 +125,7 @@ pallet-asset-manager = { path = "../asset-manager" }
pallet-assets = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.28" }
pallet-manta-pay = { path = "../manta-pay" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" }
pallet-tx-pause = { path = "../tx-pause" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" }
tempfile = "3.3.0"
xcm = { git = 'https://github.com/paritytech/polkadot.git', branch = "release-v0.9.28" }
69 changes: 68 additions & 1 deletion pallets/manta-sbt/src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

use crate::{
benchmark::precomputed_coins::TO_PRIVATE, AccountId, Box, Call, Config, Pallet, TransferPost,
benchmark::precomputed_coins::TO_PRIVATE, AccountId, Box, Call, Config, EvmAddressType,
MintType, Pallet, Pallet as MantaSBTPallet, TransferPost,
};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, vec, whitelisted_caller};
use frame_support::traits::{Currency, Get};
use frame_system::RawOrigin;
use scale_codec::Decode;
use sp_core::H160;
use sp_io::hashing::keccak_256;

mod precomputed_coins;

fn alice() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
}

benchmarks! {
where_clause { where T::AccountId: From<AccountId> + Into<AccountId> }
to_private {
Expand All @@ -45,6 +52,66 @@ benchmarks! {
}: reserve_sbt (
RawOrigin::Signed(caller)
)

change_allowlist_account{
let caller: T::AccountId = whitelisted_caller();
}: change_allowlist_account (
RawOrigin::Root,
Some(caller)
)

allowlist_evm_account {
let caller: T::AccountId = whitelisted_caller();
MantaSBTPallet::<T>::change_allowlist_account(
RawOrigin::Root.into(),
Some(caller.clone())
)?;
}: allowlist_evm_account (
RawOrigin::Signed(caller),
EvmAddressType::Bab(H160::default())
)

set_mint_chain_info {
}: set_mint_chain_info (
RawOrigin::Root,
MintType::Bab,
0,
5u32.into(),
Some(10u32.into())
)

mint_sbt_eth {
let caller: T::AccountId = whitelisted_caller();
MantaSBTPallet::<T>::change_allowlist_account(
RawOrigin::Root.into(),
Some(caller.clone())
)?;
let bab_alice = EvmAddressType::Bab(MantaSBTPallet::<T>::eth_address(&alice()));
MantaSBTPallet::<T>::set_mint_chain_info(
RawOrigin::Root.into(),
MintType::Bab,
0,
0_u32.into(),
None
)?;

MantaSBTPallet::<T>::allowlist_evm_account(
RawOrigin::Signed(caller.clone()).into(),
bab_alice,
)?;
let mint_post = TransferPost::decode(&mut &*TO_PRIVATE).unwrap();

let signature = MantaSBTPallet::<T>::eth_sign(&alice(), &mint_post.proof, 0);

}: mint_sbt_eth(
RawOrigin::Signed(caller),
Box::new(mint_post),
signature,
bab_alice,
Some(0),
Some(0),
Some(vec![0].try_into().unwrap())
)
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Loading

0 comments on commit eb538c3

Please sign in to comment.