Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vetkd context #2629

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rs/config/src/subnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ pub const ECDSA_SIGNATURE_FEE: Cycles = Cycles::new(10 * B as u128);
/// cover the cost of the subnet.
pub const SCHNORR_SIGNATURE_FEE: Cycles = Cycles::new(10 * B as u128);

/// 10B cycles corresponds to 1 SDR cent. Assuming we can create 1 signature per
/// second, that would come to 26k SDR per month if we spent the whole time
/// creating key derivations. At 13 nodes and 2k SDR per node per month this would
/// cover the cost of the subnet.
pub const VET_KD_FEE: Cycles = Cycles::new(10 * B as u128);

/// Default subnet size which is used to scale cycles cost according to a subnet replication factor.
///
/// All initial costs were calculated with the assumption that a subnet had 13 replicas.
Expand Down Expand Up @@ -407,6 +413,9 @@ pub struct CyclesAccountManagerConfig {
/// Amount to charge for a Schnorr signature.
pub schnorr_signature_fee: Cycles,

/// Amount to charge for vet KD.
pub vet_kd_fee: Cycles,

/// A linear factor of the baseline cost to be charged for HTTP requests per node.
/// The cost of an HTTP request is represented by a quadratic function due to the communication complexity of the subnet.
pub http_request_linear_baseline_fee: Cycles,
Expand Down Expand Up @@ -456,6 +465,7 @@ impl CyclesAccountManagerConfig {
duration_between_allocation_charges: Duration::from_secs(10),
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
schnorr_signature_fee: SCHNORR_SIGNATURE_FEE,
vet_kd_fee: VET_KD_FEE,
http_request_linear_baseline_fee: Cycles::new(3_000_000),
http_request_quadratic_baseline_fee: Cycles::new(60_000),
http_request_per_byte_fee: Cycles::new(400),
Expand Down Expand Up @@ -494,6 +504,7 @@ impl CyclesAccountManagerConfig {
// - non-zero cost if called from any other subnet which is not NNS subnet
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
schnorr_signature_fee: SCHNORR_SIGNATURE_FEE,
vet_kd_fee: VET_KD_FEE,
http_request_linear_baseline_fee: Cycles::new(0),
http_request_quadratic_baseline_fee: Cycles::new(0),
http_request_per_byte_fee: Cycles::new(0),
Expand Down
1 change: 1 addition & 0 deletions rs/consensus/src/idkg/payload_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ fn validate_new_signature_agreements(
let contexts = state.signature_request_contexts();
let context_map = contexts
.iter()
.filter(|(_, ctxt)| ctxt.is_ecdsa() || ctxt.is_schnorr())
.map(|(id, c)| (c.pseudo_random_id, (id, c)))
.collect::<BTreeMap<_, _>>();
for (random_id, completed) in curr_payload.signature_agreements.iter() {
Expand Down
18 changes: 13 additions & 5 deletions rs/consensus/src/idkg/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use ic_interfaces::idkg::{IDkgChangeAction, IDkgChangeSet, IDkgPool};
use ic_interfaces_state_manager::{CertifiedStateSnapshot, StateReader};
use ic_logger::{debug, warn, ReplicaLogger};
use ic_metrics::MetricsRegistry;
use ic_replicated_state::metadata_state::subnet_call_context_manager::SignWithThresholdContext;
use ic_replicated_state::metadata_state::subnet_call_context_manager::{
SignWithThresholdContext, ThresholdArguments,
};
use ic_replicated_state::ReplicatedState;
use ic_types::artifact::IDkgMessageId;
use ic_types::consensus::idkg::common::{
Expand Down Expand Up @@ -551,11 +553,17 @@ impl ThresholdSigner for ThresholdSignerImpl {
.get_state()
.signature_request_contexts()
.iter()
.flat_map(|(callback_id, context)| {
context.matched_pre_signature.map(|(_, height)| RequestId {
.flat_map(|(callback_id, context)| match &context.args {
ThresholdArguments::Ecdsa(_) | ThresholdArguments::Schnorr(_) => {
context.matched_pre_signature.map(|(_, height)| RequestId {
callback_id: *callback_id,
height,
})
}
ThresholdArguments::VetKd(args) => Some(RequestId {
callback_id: *callback_id,
height,
})
height: args.height,
}),
})
.collect();
idkg_pool
Expand Down
6 changes: 6 additions & 0 deletions rs/cycles_account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ impl CyclesAccountManager {
self.scale_cost(self.config.schnorr_signature_fee, subnet_size)
}

/// Amount to charge for vet KD.
pub fn vet_kd_fee(&self, subnet_size: usize) -> Cycles {
self.scale_cost(self.config.vet_kd_fee, subnet_size)
}

////////////////////////////////////////////////////////////////////////////
//
// Storage
Expand Down Expand Up @@ -925,6 +930,7 @@ impl CyclesAccountManager {
| CyclesUseCase::CanisterCreation
| CyclesUseCase::ECDSAOutcalls
| CyclesUseCase::SchnorrOutcalls
| CyclesUseCase::VetKd
| CyclesUseCase::HTTPOutcalls
| CyclesUseCase::DeletedCanisters
| CyclesUseCase::NonConsumed
Expand Down
2 changes: 2 additions & 0 deletions rs/execution_environment/src/execution_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,7 @@ impl ExecutionEnvironment {
match args {
ThresholdArguments::Ecdsa(_) => cam.ecdsa_signature_fee(subnet_size),
ThresholdArguments::Schnorr(_) => cam.schnorr_signature_fee(subnet_size),
ThresholdArguments::VetKd(_) => cam.vet_kd_fee(subnet_size),
}
}

Expand Down Expand Up @@ -2664,6 +2665,7 @@ impl ExecutionEnvironment {
CyclesUseCase::ECDSAOutcalls
}
ThresholdArguments::Schnorr(_) => CyclesUseCase::SchnorrOutcalls,
ThresholdArguments::VetKd(_) => CyclesUseCase::VetKd,
};
state
.metadata
Expand Down
3 changes: 3 additions & 0 deletions rs/execution_environment/tests/subnet_size_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TEST_SUBNET_SIZES: [usize; 3] = [4, 13, 34];

pub const ECDSA_SIGNATURE_FEE: Cycles = Cycles::new(10 * B as u128);
pub const SCHNORR_SIGNATURE_FEE: Cycles = Cycles::new(10 * B as u128);
pub const VET_KD_FEE: Cycles = Cycles::new(10 * B as u128);
const DEFAULT_CYCLES_PER_NODE: Cycles = Cycles::new(100 * B as u128);
const TEST_CANISTER_INSTALL_EXECUTION_INSTRUCTIONS: u64 = 0;

Expand Down Expand Up @@ -738,6 +739,7 @@ fn get_cycles_account_manager_config(subnet_type: SubnetType) -> CyclesAccountMa
// charging occurs.
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
schnorr_signature_fee: SCHNORR_SIGNATURE_FEE,
vet_kd_fee: VET_KD_FEE,
http_request_linear_baseline_fee: Cycles::new(0),
http_request_quadratic_baseline_fee: Cycles::new(0),
http_request_per_byte_fee: Cycles::new(0),
Expand Down Expand Up @@ -771,6 +773,7 @@ fn get_cycles_account_manager_config(subnet_type: SubnetType) -> CyclesAccountMa
duration_between_allocation_charges: Duration::from_secs(10),
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
schnorr_signature_fee: SCHNORR_SIGNATURE_FEE,
vet_kd_fee: VET_KD_FEE,
http_request_linear_baseline_fee: Cycles::new(3_000_000),
http_request_quadratic_baseline_fee: Cycles::new(60_000),
http_request_per_byte_fee: Cycles::new(400),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ enum CyclesUseCase {
CYCLES_USE_CASE_NON_CONSUMED = 11;
CYCLES_USE_CASE_BURNED_CYCLES = 12;
CYCLES_USE_CASE_SCHNORR_OUTCALLS = 13;
CYCLES_USE_CASE_VET_KD = 14;
}

message ConsumedCyclesByUseCase {
Expand Down
9 changes: 9 additions & 0 deletions rs/protobuf/def/state/metadata/v1/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@ message SchnorrArguments {
bytes message = 2;
}

message VetKdArguments {
types.v1.VetKdKeyId key_id = 1;
bytes derivation_id = 2;
bytes encryption_key = 3;
types.v1.NiDkgId ni_dkg_id = 4;
uint64 height = 5;
}

message ThresholdArguments {
oneof threshold_scheme {
EcdsaArguments ecdsa = 1;
SchnorrArguments schnorr = 2;
VetKdArguments vet_kd = 3;
}
}

Expand Down
3 changes: 3 additions & 0 deletions rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ pub enum CyclesUseCase {
NonConsumed = 11,
BurnedCycles = 12,
SchnorrOutcalls = 13,
VetKd = 14,
}
impl CyclesUseCase {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -767,6 +768,7 @@ impl CyclesUseCase {
Self::NonConsumed => "CYCLES_USE_CASE_NON_CONSUMED",
Self::BurnedCycles => "CYCLES_USE_CASE_BURNED_CYCLES",
Self::SchnorrOutcalls => "CYCLES_USE_CASE_SCHNORR_OUTCALLS",
Self::VetKd => "CYCLES_USE_CASE_VET_KD",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -788,6 +790,7 @@ impl CyclesUseCase {
"CYCLES_USE_CASE_NON_CONSUMED" => Some(Self::NonConsumed),
"CYCLES_USE_CASE_BURNED_CYCLES" => Some(Self::BurnedCycles),
"CYCLES_USE_CASE_SCHNORR_OUTCALLS" => Some(Self::SchnorrOutcalls),
"CYCLES_USE_CASE_VET_KD" => Some(Self::VetKd),
_ => None,
}
}
Expand Down
17 changes: 16 additions & 1 deletion rs/protobuf/src/gen/state/state.metadata.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,21 @@ pub struct SchnorrArguments {
pub message: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct VetKdArguments {
#[prost(message, optional, tag = "1")]
pub key_id: ::core::option::Option<super::super::super::types::v1::VetKdKeyId>,
#[prost(bytes = "vec", tag = "2")]
pub derivation_id: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes = "vec", tag = "3")]
pub encryption_key: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag = "4")]
pub ni_dkg_id: ::core::option::Option<super::super::super::types::v1::NiDkgId>,
#[prost(uint64, tag = "5")]
pub height: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ThresholdArguments {
#[prost(oneof = "threshold_arguments::ThresholdScheme", tags = "1, 2")]
#[prost(oneof = "threshold_arguments::ThresholdScheme", tags = "1, 2, 3")]
pub threshold_scheme: ::core::option::Option<threshold_arguments::ThresholdScheme>,
}
/// Nested message and enum types in `ThresholdArguments`.
Expand All @@ -111,6 +124,8 @@ pub mod threshold_arguments {
Ecdsa(super::EcdsaArguments),
#[prost(message, tag = "2")]
Schnorr(super::SchnorrArguments),
#[prost(message, tag = "3")]
VetKd(super::VetKdArguments),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
5 changes: 5 additions & 0 deletions rs/replicated_state/src/canister_state/system_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum CyclesUseCase {
NonConsumed = 11,
BurnedCycles = 12,
SchnorrOutcalls = 13,
VetKd = 14,
}

impl CyclesUseCase {
Expand All @@ -95,6 +96,7 @@ impl CyclesUseCase {
Self::NonConsumed => "NonConsumed",
Self::BurnedCycles => "BurnedCycles",
Self::SchnorrOutcalls => "SchnorrOutcalls",
Self::VetKd => "VetKd",
}
}
}
Expand All @@ -117,6 +119,7 @@ impl From<CyclesUseCase> for pb::CyclesUseCase {
CyclesUseCase::NonConsumed => pb::CyclesUseCase::NonConsumed,
CyclesUseCase::BurnedCycles => pb::CyclesUseCase::BurnedCycles,
CyclesUseCase::SchnorrOutcalls => pb::CyclesUseCase::SchnorrOutcalls,
CyclesUseCase::VetKd => pb::CyclesUseCase::VetKd,
}
}
}
Expand Down Expand Up @@ -144,6 +147,7 @@ impl TryFrom<pb::CyclesUseCase> for CyclesUseCase {
pb::CyclesUseCase::NonConsumed => Ok(Self::NonConsumed),
pb::CyclesUseCase::BurnedCycles => Ok(Self::BurnedCycles),
pb::CyclesUseCase::SchnorrOutcalls => Ok(Self::SchnorrOutcalls),
pb::CyclesUseCase::VetKd => Ok(Self::VetKd),
}
}
}
Expand Down Expand Up @@ -2145,6 +2149,7 @@ impl SystemState {
| CyclesUseCase::CanisterCreation
| CyclesUseCase::ECDSAOutcalls
| CyclesUseCase::SchnorrOutcalls
| CyclesUseCase::VetKd
| CyclesUseCase::HTTPOutcalls
| CyclesUseCase::DeletedCanisters
| CyclesUseCase::NonConsumed
Expand Down
1 change: 1 addition & 0 deletions rs/replicated_state/src/metadata_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ impl SubnetMetrics {
| CyclesUseCase::Uninstall
| CyclesUseCase::CanisterCreation
| CyclesUseCase::SchnorrOutcalls
| CyclesUseCase::VetKd
| CyclesUseCase::BurnedCycles => total += *cycles,
}
}
Expand Down
Loading