Working
parent
97ab6a50cc
commit
2f4e5d7c65
|
@ -4986,7 +4986,6 @@ dependencies = [
|
|||
"pallet-aura",
|
||||
"pallet-balances",
|
||||
"pallet-grandpa",
|
||||
"pallet-reward",
|
||||
"pallet-sudo",
|
||||
"pallet-template",
|
||||
"pallet-timestamp",
|
||||
|
@ -5280,21 +5279,6 @@ dependencies = [
|
|||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-reward"
|
||||
version = "4.0.0-dev"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"pallet_zkp_verify",
|
||||
"parity-scale-codec",
|
||||
"scale-info",
|
||||
"sp-core",
|
||||
"sp-io",
|
||||
"sp-runtime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-session"
|
||||
version = "4.0.0-dev"
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
[package]
|
||||
name = "pallet-reward"
|
||||
version = "4.0.0-dev"
|
||||
description = "FRAME pallet template for defining custom runtime logic."
|
||||
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
|
||||
homepage = "https://substrate.io"
|
||||
edition = "2021"
|
||||
license = "MIT-0"
|
||||
publish = false
|
||||
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
|
||||
"derive",
|
||||
] }
|
||||
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
|
||||
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
pallet_zkp_verify = { version = "4.0.0-dev", default-features = false, path = "../zkp_verify" }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-core = { version = "21.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
sp-io = { version = "23.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"frame-benchmarking?/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"scale-info/std",
|
||||
]
|
||||
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
|
||||
try-runtime = ["frame-support/try-runtime"]
|
|
@ -1 +0,0 @@
|
|||
License: MIT-0
|
|
@ -1,35 +0,0 @@
|
|||
//! Benchmarking setup for pallet-reward
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
use super::*;
|
||||
|
||||
#[allow(unused)]
|
||||
use crate::Pallet as Template;
|
||||
use frame_benchmarking::v2::*;
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn do_something() {
|
||||
let value = 100u32.into();
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
#[extrinsic_call]
|
||||
do_something(RawOrigin::Signed(caller), value);
|
||||
|
||||
assert_eq!(Something::<T>::get(), Some(value));
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn cause_error() {
|
||||
Something::<T>::put(100u32);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
#[extrinsic_call]
|
||||
cause_error(RawOrigin::Signed(caller));
|
||||
|
||||
assert_eq!(Something::<T>::get(), Some(101u32));
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
pub mod weights;
|
||||
pub use weights::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use pallet_zkp_verify::ZKPVerifyInterface;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// Configure the pallet by specifying the parameters and types on which it depends.
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// Because this pallet emits events, it depends on the runtime's definition of an event.
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
/// Type representing the weight of this pallet
|
||||
type WeightInfo: WeightInfo;
|
||||
///
|
||||
type ZKPVerify: ZKPVerifyInterface;
|
||||
}
|
||||
|
||||
// The pallet's runtime storage items.
|
||||
// https://docs.substrate.io/main-docs/build/runtime-storage/
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn something)]
|
||||
// Learn more about declaring storage items:
|
||||
// https://docs.substrate.io/main-docs/build/runtime-storage/#declaring-storage-items
|
||||
pub type Something<T> = StorageValue<_, u32>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
RewardSuccess { who: T::AccountId },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
RewardFailed,
|
||||
}
|
||||
|
||||
// Dispatchable functions allows users to interact with the pallet and invoke state changes.
|
||||
// These functions materialize as "extrinsics", which are often compared to transactions.
|
||||
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::cause_error())]
|
||||
pub fn verify_proof(
|
||||
origin: OriginFor<T>,
|
||||
|
||||
// vk: Vec<u8>,
|
||||
vk_alpha_1: Vec<u8>,
|
||||
vk_alpha_2: Vec<u8>,
|
||||
vk_beta_1_1: Vec<u8>,
|
||||
vk_beta_1_2: Vec<u8>,
|
||||
vk_beta_2_1: Vec<u8>,
|
||||
vk_beta_2_2: Vec<u8>,
|
||||
vk_gamma_1_1: Vec<u8>,
|
||||
vk_gamma_1_2: Vec<u8>,
|
||||
vk_gamma_2_1: Vec<u8>,
|
||||
vk_gamma_2_2: Vec<u8>,
|
||||
vk_delta_1_1: Vec<u8>,
|
||||
vk_delta_1_2: Vec<u8>,
|
||||
vk_delta_2_1: Vec<u8>,
|
||||
vk_delta_2_2: Vec<u8>,
|
||||
vk_gamma_abc_1_1: Vec<u8>,
|
||||
vk_gamma_abc_1_2: Vec<u8>,
|
||||
vk_gamma_abc_2_1: Vec<u8>,
|
||||
vk_gamma_abc_2_2: Vec<u8>,
|
||||
|
||||
inputs: Vec<u8>,
|
||||
|
||||
// proof: Vec<u8>,
|
||||
proof_a_1: Vec<u8>,
|
||||
proof_a_2: Vec<u8>,
|
||||
proof_b_1_1: Vec<u8>,
|
||||
proof_b_1_2: Vec<u8>,
|
||||
proof_b_2_1: Vec<u8>,
|
||||
proof_b_2_2: Vec<u8>,
|
||||
proof_c_1: Vec<u8>,
|
||||
proof_c_2: Vec<u8>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
let result = T::ZKPVerify::verify_proof(
|
||||
origin,
|
||||
vk_alpha_1,
|
||||
vk_alpha_2,
|
||||
vk_beta_1_1,
|
||||
vk_beta_1_2,
|
||||
vk_beta_2_1,
|
||||
vk_beta_2_2,
|
||||
vk_gamma_1_1,
|
||||
vk_gamma_1_2,
|
||||
vk_gamma_2_1,
|
||||
vk_gamma_2_2,
|
||||
vk_delta_1_1,
|
||||
vk_delta_1_2,
|
||||
vk_delta_2_1,
|
||||
vk_delta_2_2,
|
||||
vk_gamma_abc_1_1,
|
||||
vk_gamma_abc_1_2,
|
||||
vk_gamma_abc_2_1,
|
||||
vk_gamma_abc_2_2,
|
||||
inputs,
|
||||
proof_a_1,
|
||||
proof_a_2,
|
||||
proof_b_1_1,
|
||||
proof_b_1_2,
|
||||
proof_b_2_1,
|
||||
proof_b_2_2,
|
||||
proof_c_1,
|
||||
proof_c_2,
|
||||
);
|
||||
|
||||
if result {
|
||||
Self::deposit_event(Event::RewardSuccess { who });
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::<T>::RewardFailed.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
use crate as pallet_reward;
|
||||
use frame_support::traits::{ConstU16, ConstU64};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
BuildStorage,
|
||||
};
|
||||
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
// Configure a mock runtime to test the pallet.
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system,
|
||||
TemplateModule: pallet_reward,
|
||||
}
|
||||
);
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Nonce = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<250>;
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ConstU16<42>;
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
impl pallet_reward::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
// Build genesis storage according to the mock runtime.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
use crate::{mock::*, Error, Event};
|
||||
use frame_support::{assert_noop, assert_ok};
|
||||
|
||||
#[test]
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Go past genesis block so events get deposited
|
||||
System::set_block_number(1);
|
||||
// Dispatch a signed extrinsic.
|
||||
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42));
|
||||
// Read pallet storage and assert an expected result.
|
||||
assert_eq!(TemplateModule::something(), Some(42));
|
||||
// Assert that the correct event was deposited
|
||||
System::assert_last_event(Event::SomethingStored { something: 42, who: 1 }.into());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn correct_error_for_none_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Ensure the expected error is thrown when no value is present.
|
||||
assert_noop!(
|
||||
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
|
||||
Error::<Test>::NoneValue
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
|
||||
//! Autogenerated weights for pallet_template
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
|
||||
//! DATE: 2023-04-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `Alexs-MacBook-Pro-2.local`, CPU: `<UNKNOWN>`
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
|
||||
|
||||
// Executed Command:
|
||||
// ../../target/release/node-template
|
||||
// benchmark
|
||||
// pallet
|
||||
// --chain
|
||||
// dev
|
||||
// --pallet
|
||||
// pallet_template
|
||||
// --extrinsic
|
||||
// *
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --wasm-execution=compiled
|
||||
// --output
|
||||
// pallets/template/src/weights.rs
|
||||
// --template
|
||||
// ../../.maintain/frame-weight-template.hbs
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for pallet_template.
|
||||
pub trait WeightInfo {
|
||||
fn do_something() -> Weight;
|
||||
fn cause_error() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for pallet_template using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
/// Storage: TemplateModule Something (r:0 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn do_something() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 8_000_000 picoseconds.
|
||||
Weight::from_parts(9_000_000, 0)
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: TemplateModule Something (r:1 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn cause_error() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `32`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 6_000_000 picoseconds.
|
||||
Weight::from_parts(6_000_000, 1489)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
/// Storage: TemplateModule Something (r:0 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn do_something() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 8_000_000 picoseconds.
|
||||
Weight::from_parts(9_000_000, 0)
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: TemplateModule Something (r:1 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn cause_error() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `32`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 6_000_000 picoseconds.
|
||||
Weight::from_parts(6_000_000, 1489)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
|
@ -259,7 +259,7 @@ pub mod pallet {
|
|||
}*/
|
||||
}
|
||||
|
||||
pub trait ZKPVerifyInterface {
|
||||
/*pub trait ZKPVerifyInterface {
|
||||
fn verify_g16(
|
||||
origin: OriginFor<T>,
|
||||
|
||||
|
@ -295,8 +295,9 @@ pub mod pallet {
|
|||
proof_c_1: Vec<u8>,
|
||||
proof_c_2: Vec<u8>,
|
||||
) -> DispatchResult;
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
impl<T: Config> ZKPVerifyInterface for Pallet<T> {
|
||||
fn verify_g16(
|
||||
origin: OriginFor<T>,
|
||||
|
@ -365,5 +366,5 @@ pub mod pallet {
|
|||
proof_c_2,
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -50,7 +50,6 @@ frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, g
|
|||
# Local Dependencies
|
||||
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }
|
||||
pallet_zkp_verify = { version = "4.0.0-dev", default-features = false, path = "../pallets/zkp_verify" }
|
||||
pallet-reward = { version = "4.0.0-dev", default-features = false, path = "../pallets/reward" }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", optional = true , branch = "polkadot-v1.0.0" }
|
||||
|
|
|
@ -53,7 +53,7 @@ pub use pallet_template;
|
|||
pub use pallet_zkp_verify;
|
||||
|
||||
/// Import the reward pallet.
|
||||
pub use pallet_reward;
|
||||
//pub use pallet_reward;
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u32;
|
||||
|
@ -287,10 +287,12 @@ impl pallet_zkp_verify::Config for Runtime {
|
|||
}
|
||||
|
||||
/// Configure the pallet-reward in pallets/reward..
|
||||
/*
|
||||
impl pallet_reward::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = pallet_reward::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
*/
|
||||
|
||||
// Create the runtime by composing the FRAME pallets that were previously configured.
|
||||
construct_runtime!(
|
||||
|
@ -305,7 +307,7 @@ construct_runtime!(
|
|||
// Include the custom logic from the pallet-template in the runtime.
|
||||
TemplateModule: pallet_template,
|
||||
ZKPVerifyModule: pallet_zkp_verify,
|
||||
RewardModule: pallet_reward,
|
||||
//RewardModule: pallet_reward,
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -355,7 +357,7 @@ mod benches {
|
|||
[pallet_sudo, Sudo]
|
||||
[pallet_template, TemplateModule]
|
||||
[pallet_zkp_verify, ZKPVerifyModule]
|
||||
[pallet_reward, RewardModule]
|
||||
//[pallet_reward, eewardModule]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue