From 69318543b3049cb30595670b25d8adffd34e5de3 Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Fri, 29 Jul 2022 22:51:41 +0100 Subject: [PATCH] brainstorming --- Cargo.toml | 7 ++++ README.md | 22 +++++++++++ pallets/template/src/benchmarking.rs | 20 ---------- pallets/template/src/lib.rs | 9 ----- pallets/template/src/mock.rs | 59 ---------------------------- pallets/template/src/tests.rs | 20 ---------- 6 files changed, 29 insertions(+), 108 deletions(-) delete mode 100644 pallets/template/src/benchmarking.rs delete mode 100644 pallets/template/src/mock.rs delete mode 100644 pallets/template/src/tests.rs diff --git a/Cargo.toml b/Cargo.toml index 538fd8d..17f1f33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,10 @@ members = [ ] [profile.release] panic = "unwind" + +[profile.fast] +inherits = "release" +opt-level = 0 +lto = "off" +incremental = true +codegen-units = 256 diff --git a/README.md b/README.md index 6f12504..d1fd51e 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,25 @@ Polkadot Blockchain Academy 2022 Cohort Final Exam Project. - [ ] Anonymous quadratic system (commit-reveal) - [ ] Staking - [ ] Slashing + +## Resources + +[Commit - reveal](https://karl.tech/learning-solidity-part-2-voting/) + +Potential idea for anonymous voting + +1. Author creates a proposal and generates a keypair for this proposal +2. The public key of the proposer is distributed to voters +3. Voters encrypt their vote using the public key and sign transaction with their private key +4. Once timeout and enough votes are collected, the proposer is ready to reveal the results +5. The proposer uses their private key to decrypt votes and calculate the outcome of vote + +If the proposer reveals results before the timeout -> slashing +If the proposer tries to inside-trade the intermediate vote results -> no solution, might be worth using nominating random voters +to generate keypairs and use multi-sigs to collectively reveal the results + +Potential idea for anonymous voting 2 +1. Author publishes a proposal +2. The voters commit their decision +3. Once timeout is out, the voters have some time to reveal their choices +4. If the voters does not reveal their results -> slashing diff --git a/pallets/template/src/benchmarking.rs b/pallets/template/src/benchmarking.rs deleted file mode 100644 index d496a9f..0000000 --- a/pallets/template/src/benchmarking.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Benchmarking setup for pallet-template - -use super::*; - -#[allow(unused)] -use crate::Pallet as Template; -use frame_benchmarking::{benchmarks, whitelisted_caller}; -use frame_system::RawOrigin; - -benchmarks! { - do_something { - let s in 0 .. 100; - let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), s) - verify { - assert_eq!(Something::::get(), Some(s)); - } - - impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); -} diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index 067c7ce..88459f3 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -5,15 +5,6 @@ /// pub use pallet::*; -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs deleted file mode 100644 index 8721fe6..0000000 --- a/pallets/template/src/mock.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate as pallet_template; -use frame_support::traits::{ConstU16, ConstU64}; -use frame_system as system; -use sp_core::H256; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, -}; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, - } -); - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Call = Call; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - 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_template::Config for Test { - type Event = Event; -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default().build_storage::().unwrap().into() -} diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs deleted file mode 100644 index 2205658..0000000 --- a/pallets/template/src/tests.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::{mock::*, Error}; -use frame_support::{assert_noop, assert_ok}; - -#[test] -fn it_works_for_default_value() { - new_test_ext().execute_with(|| { - // Dispatch a signed extrinsic. - assert_ok!(TemplateModule::do_something(Origin::signed(1), 42)); - // Read pallet storage and assert an expected result. - assert_eq!(TemplateModule::something(), Some(42)); - }); -} - -#[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(Origin::signed(1)), Error::::NoneValue); - }); -}