Skip to content

Commit

Permalink
Rename sig scheme and increase rewards (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovesh authored Jul 3, 2024
1 parent 1cf578f commit 2b74bc6
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 57 deletions.
36 changes: 18 additions & 18 deletions pallets/core/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,26 @@ where
at: Option<BlockHash>,
) -> RpcResult<BTreeSet<TrustRegistrySchemaId>>;

#[method(name = "core_mods_bddt16PublicKeyWithParams")]
async fn bddt16_public_key_with_params(
#[method(name = "core_mods_bbdt16PublicKeyWithParams")]
async fn bbdt16_public_key_with_params(
&self,
id: offchain_signatures::SignaturePublicKeyStorageKey,
at: Option<BlockHash>,
) -> RpcResult<Option<offchain_signatures::BDDT16PublicKeyWithParams<T::T>>>;
) -> RpcResult<Option<offchain_signatures::BBDT16PublicKeyWithParams<T::T>>>;

#[method(name = "core_mods_bddt16ParamsByDid")]
async fn bddt16_params_by_did(
#[method(name = "core_mods_bbdt16ParamsByDid")]
async fn bbdt16_params_by_did(
&self,
owner: offchain_signatures::SignatureParamsOwner,
at: Option<BlockHash>,
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BDDT16Parameters<T::T>>>;
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BBDT16Parameters<T::T>>>;

#[method(name = "core_mods_bddt16PublicKeysByDid")]
async fn bddt16_public_keys_by_did(
#[method(name = "core_mods_bbdt16PublicKeysByDid")]
async fn bbdt16_public_keys_by_did(
&self,
did: did::Did,
at: Option<BlockHash>,
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BDDT16PublicKeyWithParams<T::T>>>;
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BBDT16PublicKeyWithParams<T::T>>>;
}

/// A struct that implements the [`CoreModsApi`].
Expand Down Expand Up @@ -663,44 +663,44 @@ where
.map_err(Into::into)
}

async fn bddt16_public_key_with_params(
async fn bbdt16_public_key_with_params(
&self,
id: offchain_signatures::SignaturePublicKeyStorageKey,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Option<offchain_signatures::BDDT16PublicKeyWithParams<T::T>>> {
) -> RpcResult<Option<offchain_signatures::BBDT16PublicKeyWithParams<T::T>>> {
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(||
// If the block hash is not supplied assume the best block.
self.client.info().best_hash));
api.bddt16_public_key_with_params(&at, id)
api.bbdt16_public_key_with_params(&at, id)
.map_err(Error)
.map_err(Into::into)
}

async fn bddt16_params_by_did(
async fn bbdt16_params_by_did(
&self,
owner: offchain_signatures::SignatureParamsOwner,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BDDT16Parameters<T::T>>> {
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BBDT16Parameters<T::T>>> {
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(||
// If the block hash is not supplied assume the best block.
self.client.info().best_hash));
api.bddt16_params_by_did(&at, owner)
api.bbdt16_params_by_did(&at, owner)
.map_err(Error)
.map_err(Into::into)
}

async fn bddt16_public_keys_by_did(
async fn bbdt16_public_keys_by_did(
&self,
did: did::Did,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BDDT16PublicKeyWithParams<T::T>>> {
) -> RpcResult<BTreeMap<IncId, offchain_signatures::BBDT16PublicKeyWithParams<T::T>>> {
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(||
// If the block hash is not supplied assume the best block.
self.client.info().best_hash));
api.bddt16_public_keys_by_did(&at, did)
api.bbdt16_public_keys_by_did(&at, did)
.map_err(Error)
.map_err(Into::into)
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/core/src/common/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub trait Limits: Clone + Eq {
type MaxBBSPublicKeySize: Size;
/// Maximum byte size of the `BBS+` (fixed size) public key. This depends only on the chosen elliptic curve.
type MaxBBSPlusPublicKeySize: Size;
/// Maximum byte size of the `BDDT16` (fixed size) public key. This depends only on the chosen elliptic curve.
type MaxBDDT16PublicKeySize: Size;
/// Maximum byte size of the `BBDT16` (fixed size) public key. This depends only on the chosen elliptic curve.
type MaxBBDT16PublicKeySize: Size;
/// Maximum byte size of the `PS` public key. This depends on the chosen elliptic curve and the number
/// of messages that can be signed.
type MaxPSPublicKeySize: Size;
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Limits for () {

type MaxBBSPublicKeySize = NoLimit;
type MaxBBSPlusPublicKeySize = NoLimit;
type MaxBDDT16PublicKeySize = NoLimit;
type MaxBBDT16PublicKeySize = NoLimit;
type MaxPSPublicKeySize = NoLimit;

type MaxMasterMembers = NoLimit;
Expand Down
2 changes: 1 addition & 1 deletion pallets/core/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<T: Types, L: Limits> Limits for CombineTypesAndLimits<T, L> {
type MaxBBSPublicKeySize = L::MaxBBSPublicKeySize;
type MaxBBSPlusPublicKeySize = L::MaxBBSPlusPublicKeySize;
type MaxPSPublicKeySize = L::MaxPSPublicKeySize;
type MaxBDDT16PublicKeySize = L::MaxBDDT16PublicKeySize;
type MaxBBDT16PublicKeySize = L::MaxBBDT16PublicKeySize;

type MaxMasterMembers = L::MaxMasterMembers;
type MaxPolicyControllers = L::MaxPolicyControllers;
Expand Down
4 changes: 2 additions & 2 deletions pallets/core/src/modules/offchain_signatures/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Module to store offchain signature keys and parameters for different signature schemes.
//! Currently, can be either `BBS`, `BBS+`, `Pointcheval-Sanders` or `BDDT16`.
//! For `BBS`, `BBS+` and `Pointcheval-Sanders`, the public key is in group G2 but for `BDDT16`, it's
//! Currently, can be either `BBS`, `BBS+`, `Pointcheval-Sanders` or `BBDT16`.
//! For `BBS`, `BBS+` and `Pointcheval-Sanders`, the public key is in group G2 but for `BBDT16`, it's
//! in group G1 and used to verify the proof of validity of MAC (and related proofs) but not the MAC itself.
use crate::{
Expand Down
14 changes: 7 additions & 7 deletions pallets/core/src/modules/offchain_signatures/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub type SignatureParamsStorageKey = (SignatureParamsOwner, IncId);
pub type BBSPublicKeyWithParams<T> = (BBSPublicKey<T>, Option<BBSParameters<T>>);
pub type BBSPlusPublicKeyWithParams<T> = (BBSPlusPublicKey<T>, Option<BBSPlusParameters<T>>);
pub type PSPublicKeyWithParams<T> = (PSPublicKey<T>, Option<PSParameters<T>>);
pub type BDDT16PublicKeyWithParams<T> = (BDDT16PublicKey<T>, Option<BDDT16Parameters<T>>);
pub type BBDT16PublicKeyWithParams<T> = (BBDT16PublicKey<T>, Option<BBDT16Parameters<T>>);

/// Signature parameters. Currently can be either `BBS`, `BBS+` or `Pointcheval-Sanders`.
#[derive(
Expand All @@ -73,8 +73,8 @@ pub enum OffchainSignatureParams<T: Limits> {
BBSPlus(BBSPlusParameters<T>),
/// Signature parameters for the Pointcheval-Sanders signature scheme.
PS(PSParameters<T>),
/// Signature parameters for the BDDT16 signature scheme.
BDDT16(BDDT16Parameters<T>),
/// Signature parameters for the BBDT16 signature scheme.
BBDT16(BBDT16Parameters<T>),
}

impl<T: Limits> OffchainSignatureParams<T> {
Expand All @@ -93,8 +93,8 @@ impl<T: Limits> OffchainSignatureParams<T> {
self.try_into().ok()
}

/// Returns underlying parameters if it corresponds to the BDDT16 scheme.
pub fn into_bddt16(self) -> Option<BDDT16Parameters<T>> {
/// Returns underlying parameters if it corresponds to the BBDT16 scheme.
pub fn into_bbdt16(self) -> Option<BBDT16Parameters<T>> {
self.try_into().ok()
}

Expand All @@ -104,7 +104,7 @@ impl<T: Limits> OffchainSignatureParams<T> {
Self::BBS(params) => &params.bytes[..],
Self::BBSPlus(params) => &params.bytes[..],
Self::PS(params) => &params.bytes[..],
Self::BDDT16(params) => &params.bytes[..],
Self::BBDT16(params) => &params.bytes[..],
}
}

Expand All @@ -114,7 +114,7 @@ impl<T: Limits> OffchainSignatureParams<T> {
Self::BBS(params) => params.label.as_ref().map(|slice| &slice[..]),
Self::BBSPlus(params) => params.label.as_ref().map(|slice| &slice[..]),
Self::PS(params) => params.label.as_ref().map(|slice| &slice[..]),
Self::BDDT16(params) => params.label.as_ref().map(|slice| &slice[..]),
Self::BBDT16(params) => params.label.as_ref().map(|slice| &slice[..]),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions pallets/core/src/modules/offchain_signatures/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{

pub type SignaturePublicKeyStorageKey = (Did, IncId);

/// Public key for different signature schemes. Currently, can be either `BBS`, `BBS+`, `Pointcheval-Sanders` or `BDDT16`.
/// Public key for different signature schemes. Currently, can be either `BBS`, `BBS+`, `Pointcheval-Sanders` or `BBDT16`.
#[derive(
scale_info_derive::TypeInfo, Encode, Decode, Clone, PartialEq, Eq, DebugNoBound, MaxEncodedLen,
)]
Expand All @@ -33,9 +33,9 @@ pub enum OffchainPublicKey<T: Limits> {
BBSPlus(BBSPlusPublicKey<T>),
/// Public key for the Pointcheval-Sanders signature scheme.
PS(PSPublicKey<T>),
/// Public key for the BDDt16 signature scheme. This will be in group G1 and will be used to verify
/// Public key for the BBDT16 signature scheme. This will be in group G1 and will be used to verify
/// the validity proof of the MAC and not the MAC itself.
BDDT16(BDDT16PublicKey<T>),
BBDT16(BBDT16PublicKey<T>),
}

impl<T: Limits> OffchainPublicKey<T> {
Expand All @@ -54,8 +54,8 @@ impl<T: Limits> OffchainPublicKey<T> {
self.try_into().ok()
}

/// Returns underlying public key if it corresponds to the BDDT16 scheme.
pub fn into_bddt16(self) -> Option<BDDT16PublicKey<T>> {
/// Returns underlying public key if it corresponds to the BBDT16 scheme.
pub fn into_bbdt16(self) -> Option<BBDT16PublicKey<T>> {
self.try_into().ok()
}

Expand All @@ -65,7 +65,7 @@ impl<T: Limits> OffchainPublicKey<T> {
Self::BBS(key) => &key.bytes[..],
Self::BBSPlus(key) => &key.bytes[..],
Self::PS(key) => &key.bytes[..],
Self::BDDT16(key) => &key.bytes[..],
Self::BBDT16(key) => &key.bytes[..],
}
}

Expand All @@ -75,7 +75,7 @@ impl<T: Limits> OffchainPublicKey<T> {
Self::BBS(bbs_key) => &bbs_key.params_ref,
Self::BBSPlus(bbs_plus_key) => &bbs_plus_key.params_ref,
Self::PS(ps_key) => &ps_key.params_ref,
Self::BDDT16(key) => &key.params_ref,
Self::BBDT16(key) => &key.params_ref,
};

opt.as_ref()
Expand All @@ -87,7 +87,7 @@ impl<T: Limits> OffchainPublicKey<T> {
Self::BBS(_) => matches!(params, OffchainSignatureParams::BBS(_)),
Self::BBSPlus(_) => matches!(params, OffchainSignatureParams::BBSPlus(_)),
Self::PS(_) => matches!(params, OffchainSignatureParams::PS(_)),
Self::BDDT16(_) => matches!(params, OffchainSignatureParams::BDDT16(_)),
Self::BBDT16(_) => matches!(params, OffchainSignatureParams::BBDT16(_)),
}
}

Expand Down
10 changes: 5 additions & 5 deletions pallets/core/src/modules/offchain_signatures/schemes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def_signature_scheme_key_and_params! {
}

def_signature_scheme_key_and_params! {
for BDDT16:
/// Public key for the BDDT16 signature scheme.
BDDT16PublicKey<MaxBDDT16PublicKeySize>,
/// Signature parameters for the BDDT16 signature scheme.
BDDT16Parameters<MaxOffchainParamsBytesSize>
for BBDT16:
/// Public key for the BBDT16 signature scheme.
BBDT16PublicKey<MaxBBDT16PublicKeySize>,
/// Signature parameters for the BBDT16 signature scheme.
BBDT16Parameters<MaxOffchainParamsBytesSize>
}
6 changes: 3 additions & 3 deletions pallets/core/src/modules/offchain_signatures/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ macro_rules! with_each_scheme {
$($tt)+
}

mod bddt16 {
mod bbdt16 {
use super::*;
use BDDT16PublicKey as $key;
use BDDT16Parameters as $params;
use BBDT16PublicKey as $key;
use BBDT16Parameters as $params;

$($tt)+
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/core/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ sp_api::decl_runtime_apis! {
reg_id: TrustRegistryId
) -> BTreeSet<TrustRegistrySchemaId>;

fn bddt16_public_key_with_params(id: offchain_signatures::SignaturePublicKeyStorageKey) -> Option<offchain_signatures::BDDT16PublicKeyWithParams<T>>;
fn bbdt16_public_key_with_params(id: offchain_signatures::SignaturePublicKeyStorageKey) -> Option<offchain_signatures::BBDT16PublicKeyWithParams<T>>;

fn bddt16_params_by_did(owner: offchain_signatures::SignatureParamsOwner) -> BTreeMap<IncId, offchain_signatures::BDDT16Parameters<T>>;
fn bbdt16_params_by_did(owner: offchain_signatures::SignatureParamsOwner) -> BTreeMap<IncId, offchain_signatures::BBDT16Parameters<T>>;

fn bddt16_public_keys_by_did(did: crate::did::Did) -> BTreeMap<IncId, offchain_signatures::BDDT16PublicKeyWithParams<T>>;
fn bbdt16_public_keys_by_did(did: crate::did::Did) -> BTreeMap<IncId, offchain_signatures::BBDT16PublicKeyWithParams<T>>;
}
}
2 changes: 1 addition & 1 deletion pallets/core/src/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl crate::common::Limits for Test {
type MaxBBSPublicKeySize = ConstU32<128>;
type MaxBBSPlusPublicKeySize = ConstU32<128>;
type MaxPSPublicKeySize = ConstU32<128>;
type MaxBDDT16PublicKeySize = ConstU32<128>;
type MaxBBDT16PublicKeySize = ConstU32<128>;

type MaxMasterMembers = ConstU32<100>;
type MaxPolicyControllers = ConstU32<15>;
Expand Down
20 changes: 14 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("dock-pos-dev-runtime"),
impl_name: create_runtime_str!("Dock"),
authoring_version: 1,
spec_version: 58,
spec_version: 59,
impl_version: 2,
transaction_version: 2,
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -846,7 +846,7 @@ impl common::Limits for Runtime {
type MaxPSPublicKeySize = ConstU32<65536>;
type MaxBBSPublicKeySize = ConstU32<256>;
type MaxBBSPlusPublicKeySize = ConstU32<256>;
type MaxBDDT16PublicKeySize = ConstU32<256>;
type MaxBBDT16PublicKeySize = ConstU32<256>;

/// 128 bytes, for large labels, hash of a label can be used
type MaxOffchainParamsLabelSize = ConstU32<128>;
Expand Down Expand Up @@ -1566,12 +1566,20 @@ pallet_staking_reward_curve::build! {
);
}

/// Pay high-rate rewards for 1 month (in eras) after the upgrade.
const POST_UPGRADE_HIGH_RATE_DURATION: DurationInEras =
DurationInEras::new_non_zero((30 * DAY / EPOCH_DURATION_IN_BLOCKS / SESSIONS_PER_ERA) as u16);

#[cfg(not(feature = "small_durations"))]
// 1 era lasts for 12h.
const_assert_eq!(POST_UPGRADE_HIGH_RATE_DURATION.0.get(), 30 * 2);

parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const HighRateRewardDecayPct: Percent = Percent::from_percent(50);
pub const LowRateRewardDecayPct: Percent = Percent::from_percent(25);
pub const TreasuryRewardsPct: Percent = Percent::from_percent(50);
pub const PostUpgradeHighRateDuration: Option<DurationInEras> = None;
pub const PostUpgradeHighRateDuration: Option<DurationInEras> = Some(POST_UPGRADE_HIGH_RATE_DURATION);
}

impl dock_staking_rewards::Config for Runtime {
Expand Down Expand Up @@ -2478,18 +2486,18 @@ impl_runtime_apis! {
by.resolve_to_schema_ids_in_registry::<Runtime>(reg_id)
}

fn bddt16_public_key_with_params((did, key_id): offchain_signatures::SignaturePublicKeyStorageKey) -> Option<offchain_signatures::BDDT16PublicKeyWithParams<Runtime>> {
fn bbdt16_public_key_with_params((did, key_id): offchain_signatures::SignaturePublicKeyStorageKey) -> Option<offchain_signatures::BBDT16PublicKeyWithParams<Runtime>> {
OffchainSignatures::did_public_key(did, key_id)
.and_then(CheckedConversion::checked_into)
}

fn bddt16_params_by_did(owner: offchain_signatures::SignatureParamsOwner) -> BTreeMap<IncId, offchain_signatures::BDDT16Parameters<Runtime>> {
fn bbdt16_params_by_did(owner: offchain_signatures::SignatureParamsOwner) -> BTreeMap<IncId, offchain_signatures::BBDT16Parameters<Runtime>> {
OffchainSignatures::did_params(&owner)
.filter_map(checked_convert_indexed_item)
.collect()
}

fn bddt16_public_keys_by_did(did: did::Did) -> BTreeMap<IncId, offchain_signatures::BDDT16PublicKeyWithParams<Runtime>> {
fn bbdt16_public_keys_by_did(did: did::Did) -> BTreeMap<IncId, offchain_signatures::BBDT16PublicKeyWithParams<Runtime>> {
OffchainSignatures::did_public_keys(&did)
.filter_map(checked_convert_indexed_item)
.collect()
Expand Down

0 comments on commit 2b74bc6

Please sign in to comment.