From f3431c6302686314bb06341e24b81bad6f477229 Mon Sep 17 00:00:00 2001 From: Zhou Fang Date: Mon, 6 Apr 2026 15:29:43 -0700 Subject: [PATCH 1/3] feat!: make `t` and `allowed_delta` configurable --- crates/e2e-tests/src/e2e_flow.rs | 27 ++++++++++++++ crates/hashi/src/lib.rs | 11 +++--- crates/hashi/src/mpc/mpc_except_signing.rs | 31 +++++++++------- .../hashi/src/mpc/mpc_except_signing_tests.rs | 37 +++++++++++++++---- crates/hashi/src/onchain/mod.rs | 8 ++++ crates/hashi/src/onchain/types.rs | 22 +++++++++++ crates/internal-tools/src/key_recovery.rs | 8 +++- packages/hashi/sources/core/mpc_config.move | 36 ++++++++++++++++++ .../core/proposal/types/update_config.move | 3 +- packages/hashi/sources/hashi.move | 1 + 10 files changed, 154 insertions(+), 30 deletions(-) create mode 100644 packages/hashi/sources/core/mpc_config.move diff --git a/crates/e2e-tests/src/e2e_flow.rs b/crates/e2e-tests/src/e2e_flow.rs index 16b198e05..2e12d052d 100644 --- a/crates/e2e-tests/src/e2e_flow.rs +++ b/crates/e2e-tests/src/e2e_flow.rs @@ -1314,6 +1314,33 @@ mod tests { Ok(()) } + #[tokio::test] + async fn test_mpc_config_defaults_match_rust() -> Result<()> { + init_test_logging(); + + let networks = TestNetworksBuilder::new().with_nodes(1).build().await?; + networks.hashi_network.nodes()[0] + .wait_for_mpc_key(Duration::from_secs(60)) + .await?; + + use hashi::onchain::types::DEFAULT_MPC_ALLOWED_DELTA; + use hashi::onchain::types::DEFAULT_MPC_THRESHOLD_BASIS_POINTS; + + let hashi = networks.hashi_network.nodes()[0].hashi(); + let threshold_bps = hashi.onchain_state().mpc_threshold_basis_points(); + let allowed_delta = hashi.onchain_state().mpc_allowed_delta(); + + assert_eq!( + threshold_bps, DEFAULT_MPC_THRESHOLD_BASIS_POINTS, + "on-chain mpc_threshold_basis_points ({threshold_bps}) != Rust default ({DEFAULT_MPC_THRESHOLD_BASIS_POINTS})" + ); + assert_eq!( + allowed_delta, DEFAULT_MPC_ALLOWED_DELTA, + "on-chain mpc_allowed_delta ({allowed_delta}) != Rust default ({DEFAULT_MPC_ALLOWED_DELTA})" + ); + Ok(()) + } + /// Verify that a withdrawal can spend a change output whose producing /// transaction is mined on Bitcoin but not yet confirmed on Sui. The /// actual Bitcoin confirmation count must be queried from the node diff --git a/crates/hashi/src/lib.rs b/crates/hashi/src/lib.rs index 79d53388d..8db089cd5 100644 --- a/crates/hashi/src/lib.rs +++ b/crates/hashi/src/lib.rs @@ -28,9 +28,6 @@ pub mod tls; pub mod utxo_pool; pub mod withdrawals; -/// The allowed delta for weight reduction in basis points (800 means 8%). -/// This matches Sui's `random_beacon_reduction_allowed_delta` configuration. -const WEIGHT_REDUCTION_ALLOWED_DELTA: u16 = 800; // TODO: Tune based on production workload. const BATCH_SIZE_PER_WEIGHT: u16 = 10; @@ -220,7 +217,10 @@ impl Hashi { protocol_type: mpc::types::ProtocolType, ) -> anyhow::Result { let state = self.onchain_state().state(); - let committee_set = &state.hashi().committees; + let hashi = state.hashi(); + let committee_set = &hashi.committees; + let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); + let allowed_delta = hashi.config.mpc_allowed_delta(); let session_id = mpc::SessionId::new(self.config.sui_chain_id(), epoch, &protocol_type); let encryption_key = self.config.encryption_private_key()?; self.db @@ -261,7 +261,8 @@ impl Hashi { encryption_key, signing_key, store, - WEIGHT_REDUCTION_ALLOWED_DELTA, + threshold_basis_points, + allowed_delta, chain_id, self.config.test_weight_divisor, batch_size_per_weight, diff --git a/crates/hashi/src/mpc/mpc_except_signing.rs b/crates/hashi/src/mpc/mpc_except_signing.rs index 4998606f4..63c17c616 100644 --- a/crates/hashi/src/mpc/mpc_except_signing.rs +++ b/crates/hashi/src/mpc/mpc_except_signing.rs @@ -74,6 +74,7 @@ const ERR_PUBLISH_CERT_FAILED: &str = "Failed to publish certificate"; const EXPECT_THRESHOLD_VALIDATED: &str = "Threshold already validated"; const EXPECT_THRESHOLD_MET: &str = "Already checked earlier that threshold is met"; const EXPECT_SERIALIZATION_SUCCESS: &str = "Serialization should always succeed"; +const MAX_BASIS_POINTS: u32 = 10000; pub struct MpcManager { // Immutable during the epoch @@ -120,6 +121,7 @@ impl MpcManager { encryption_key: PrivateKey, signing_key: Bls12381PrivateKey, public_message_store: Box, + threshold_basis_points: u16, allowed_delta: u16, chain_id: &str, weight_divisor: Option, @@ -141,8 +143,12 @@ impl MpcManager { .get(&epoch) .ok_or_else(|| MpcError::InvalidConfig(format!("no committee for epoch {epoch}")))? .clone(); - // TODO: Pass t and f as arguments instead of computing them - let (nodes, threshold) = build_reduced_nodes(&committee, allowed_delta, weight_divisor)?; + let (nodes, threshold) = build_reduced_nodes( + &committee, + threshold_basis_points, + allowed_delta, + weight_divisor, + )?; let total_weight = nodes.total_weight(); let max_faulty = ((total_weight - threshold) / 2).min(threshold - 1); let dkg_config = MpcConfig::new(epoch, nodes, threshold, max_faulty)?; @@ -196,8 +202,12 @@ impl MpcManager { }; let (previous_nodes, previous_threshold) = match previous_committee.as_ref() { Some(prev_committee) => { - let (nodes, threshold) = - build_reduced_nodes(prev_committee, allowed_delta, weight_divisor)?; + let (nodes, threshold) = build_reduced_nodes( + prev_committee, + threshold_basis_points, + allowed_delta, + weight_divisor, + )?; (Some(nodes), Some(threshold)) } None => (None, None), @@ -3579,17 +3589,9 @@ fn compute_messages_hash(messages: &Messages) -> MessageHash { MessageHash::from(Blake2b256::digest(&bytes).digest) } -fn compute_bft_threshold(total_weight: u16) -> MpcResult { - if total_weight == 0 { - return Err(MpcError::InvalidConfig( - "committee has zero total weight".into(), - )); - } - Ok((total_weight - 1) / 3 + 1) -} - fn build_reduced_nodes( committee: &Committee, + threshold_basis_points: u16, allowed_delta: u16, test_weight_divisor: u16, ) -> MpcResult<(Nodes, u16)> { @@ -3604,7 +3606,8 @@ fn build_reduced_nodes( }) .collect(); let total_weight: u16 = nodes_vec.iter().map(|n| n.weight).sum(); - let threshold = compute_bft_threshold(total_weight)?; + let threshold = + (total_weight as u32 * threshold_basis_points as u32).div_ceil(MAX_BASIS_POINTS) as u16; Nodes::new_reduced(nodes_vec, threshold, allowed_delta, 1) .map_err(|e| MpcError::CryptoError(e.to_string())) } diff --git a/crates/hashi/src/mpc/mpc_except_signing_tests.rs b/crates/hashi/src/mpc/mpc_except_signing_tests.rs index 5b66a2486..cffc77ad2 100644 --- a/crates/hashi/src/mpc/mpc_except_signing_tests.rs +++ b/crates/hashi/src/mpc/mpc_except_signing_tests.rs @@ -24,6 +24,7 @@ use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; +const TEST_THRESHOLD_BASIS_POINTS: u16 = 3333; /// Use 0 for allowed_delta in tests to disable weight reduction. const TEST_ALLOWED_DELTA: u16 = 0; /// Use 1 for test_weight_divisor in unit tests (they already use small weights). @@ -287,6 +288,7 @@ impl TestSetup { self.encryption_keys[validator_index].clone(), self.signing_keys[validator_index].clone(), store, + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -900,6 +902,7 @@ fn test_mpc_manager_new_from_committee_set() { encryption_key, signing_key, Box::new(MockPublicMessagesStore), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -963,6 +966,7 @@ fn test_mpc_manager_new_fails_if_no_committee_for_epoch() { encryption_keys[0].clone(), signing_keys[0].clone(), Box::new(MockPublicMessagesStore), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, "test", None, @@ -986,7 +990,8 @@ fn test_mpc_manager_new_with_weighted_committee() { let manager = setup.create_manager(0); - // With total_weight=15: max_faulty = (15-1)/3 = 4, threshold = 5 + // With total_weight=15, threshold=ceil(15*3333/10000)=ceil(4.9995)=5 + // max_faulty = min((15-5)/2, 5-1) = min(5, 4) = 4 assert_eq!(manager.mpc_config.threshold, 5); assert_eq!(manager.mpc_config.max_faulty, 4); } @@ -1271,7 +1276,7 @@ fn test_complete_dkg_success() { let mut rng = rand::thread_rng(); // Use different weights: [3, 2, 4, 1, 2] (total = 12) - // threshold = (12 - 1) / 3 + 1 = 4 + // threshold = ceil(12 * 3333 / 10000) = 4 let weights = [3, 2, 4, 1, 2]; let setup = TestSetup::with_weights(&weights); @@ -4892,8 +4897,8 @@ struct RotationTestSetup { impl RotationTestSetup { /// Creates a rotation test setup with weighted validators and completed DKG. - /// Uses weights [3, 2, 4, 1, 2] (total = 12, threshold = 4). - /// Dealers are validators 0, 1, 4 (total weight = 7 >= threshold). + /// Uses weights [3, 2, 4, 1, 2] (total = 12, threshold = ceil(12*3333/10000) = 4). + /// Dealers are validators 0, 1, 4 (total weight = 7 >= threshold + max_faulty = 7). fn new() -> Self { let mut rng = rand::thread_rng(); let weights = [3, 2, 4, 1, 2]; @@ -4952,8 +4957,13 @@ impl RotationTestSetup { /// This matches `run_as_party` behavior during live DKG. fn threshold_dealer_addresses(&self) -> Vec
{ let committee = self.setup.committee(); - let (nodes, threshold) = - build_reduced_nodes(committee, TEST_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR).unwrap(); + let (nodes, threshold) = build_reduced_nodes( + committee, + TEST_THRESHOLD_BASIS_POINTS, + TEST_ALLOWED_DELTA, + TEST_WEIGHT_DIVISOR, + ) + .unwrap(); let mut result = Vec::new(); let mut weight_sum = 0u16; for addr in self.certificates.keys() { @@ -4973,8 +4983,13 @@ impl RotationTestSetup { fn prepare_for_rotation(&self, manager: &mut MpcManager) { let previous_committee = self.setup.committee_set.previous_committee().cloned(); if let Some(ref prev) = previous_committee { - let (nodes, threshold) = - build_reduced_nodes(prev, TEST_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR).unwrap(); + let (nodes, threshold) = build_reduced_nodes( + prev, + TEST_THRESHOLD_BASIS_POINTS, + TEST_ALLOWED_DELTA, + TEST_WEIGHT_DIVISOR, + ) + .unwrap(); manager.previous_nodes = Some(nodes); manager.previous_threshold = Some(threshold); } @@ -6118,6 +6133,7 @@ async fn test_prepare_previous_output_for_new_member() { new_member_encryption_key, new_member_signing_key, Box::new(InMemoryPublicMessagesStore::new()), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7258,6 +7274,7 @@ fn test_reconstruct_from_dkg_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[shifted_member_index].clone(), rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7420,6 +7437,7 @@ fn test_reconstruct_from_dkg_certificates_stops_at_threshold() { setup.encryption_keys[target_index].clone(), setup.signing_keys[target_index].clone(), Box::new(store), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7500,6 +7518,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[dealer_idx].clone(), rotation_setup.setup.signing_keys[dealer_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7531,6 +7550,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[other_idx].clone(), rotation_setup.setup.signing_keys[other_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7618,6 +7638,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[shifted_member_index].clone(), rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), + TEST_THRESHOLD_BASIS_POINTS, TEST_ALLOWED_DELTA, TEST_CHAIN_ID, None, diff --git a/crates/hashi/src/onchain/mod.rs b/crates/hashi/src/onchain/mod.rs index 278327e5b..923e92137 100644 --- a/crates/hashi/src/onchain/mod.rs +++ b/crates/hashi/src/onchain/mod.rs @@ -394,6 +394,14 @@ impl OnchainState { self.state().hashi().config.bitcoin_confirmation_threshold() } + pub fn mpc_threshold_basis_points(&self) -> u16 { + self.state().hashi().config.mpc_threshold_basis_points() + } + + pub fn mpc_allowed_delta(&self) -> u16 { + self.state().hashi().config.mpc_allowed_delta() + } + pub fn bridge_service_client( &self, validator: &Address, diff --git a/crates/hashi/src/onchain/types.rs b/crates/hashi/src/onchain/types.rs index a8cdf68fb..8c58fab99 100644 --- a/crates/hashi/src/onchain/types.rs +++ b/crates/hashi/src/onchain/types.rs @@ -469,6 +469,10 @@ pub struct Config { // This constant mirrors the value in btc_config.move and must be kept in sync. const DUST_RELAY_MIN_VALUE: u64 = 546; +// These mirror the defaults in mpc_config.move and must be kept in sync. +pub const DEFAULT_MPC_THRESHOLD_BASIS_POINTS: u16 = 3333; +pub const DEFAULT_MPC_ALLOWED_DELTA: u16 = 800; + impl Config { /// Minimum deposit amount, mirroring the floor logic in btc_config.move. pub fn bitcoin_deposit_minimum(&self) -> u64 { @@ -510,6 +514,24 @@ impl Config { _ => 6, } } + + pub fn mpc_threshold_basis_points(&self) -> u16 { + match self.config.get("mpc_threshold_basis_points") { + Some(ConfigValue::U64(v)) => { + u16::try_from(*v).expect("mpc_threshold_basis_points exceeds u16::MAX") + } + _ => DEFAULT_MPC_THRESHOLD_BASIS_POINTS, + } + } + + pub fn mpc_allowed_delta(&self) -> u16 { + match self.config.get("mpc_allowed_delta") { + Some(ConfigValue::U64(v)) => { + u16::try_from(*v).expect("mpc_allowed_delta exceeds u16::MAX") + } + _ => DEFAULT_MPC_ALLOWED_DELTA, + } + } } #[derive(Debug)] diff --git a/crates/internal-tools/src/key_recovery.rs b/crates/internal-tools/src/key_recovery.rs index 8bd8f846d..190c33069 100644 --- a/crates/internal-tools/src/key_recovery.rs +++ b/crates/internal-tools/src/key_recovery.rs @@ -113,14 +113,18 @@ pub async fn run(args: Args, onchain_state: &OnchainState, chain_id: &str) -> an let session_id = SessionId::new(chain_id, reconstruction_epoch, &ProtocolType::KeyRotation); let mut manager = { let state = onchain_state.state(); + let hashi = state.hashi(); + let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); + let allowed_delta = hashi.config.mpc_allowed_delta(); MpcManager::new( validator_address, - &state.hashi().committees, + &hashi.committees, session_id, encryption_key, dummy_signing_key.clone(), Box::new(store), - 800, // allowed_delta (same as devnet) + threshold_basis_points, + allowed_delta, chain_id, None, // weight_divisor 0, // batch_size_per_weight (unused for reconstruction) diff --git a/packages/hashi/sources/core/mpc_config.move b/packages/hashi/sources/core/mpc_config.move new file mode 100644 index 000000000..d2c86f310 --- /dev/null +++ b/packages/hashi/sources/core/mpc_config.move @@ -0,0 +1,36 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +module hashi::mpc_config; + +use hashi::{config::Config, config_value}; + +const DEFAULT_THRESHOLD_BASIS_POINTS: u64 = 3333; + +const MAX_BPS: u64 = 10000; + +/// Default allowed delta for weight reduction. +const DEFAULT_ALLOWED_DELTA: u64 = 800; + +#[allow(implicit_const_copy)] +public(package) fun is_valid_config_entry( + key: &std::string::String, + value: &config_value::Value, +): bool { + let k = key.as_bytes(); + if (k == &b"mpc_threshold_basis_points") { + value.is_u64() && (*value).as_u64() > 0 && (*value).as_u64() <= MAX_BPS + } else if (k == &b"mpc_allowed_delta") { + value.is_u64() && (*value).as_u64() <= MAX_BPS + } else { + false + } +} + +public(package) fun init_defaults(config: &mut Config) { + config.upsert( + b"mpc_threshold_basis_points", + config_value::new_u64(DEFAULT_THRESHOLD_BASIS_POINTS), + ); + config.upsert(b"mpc_allowed_delta", config_value::new_u64(DEFAULT_ALLOWED_DELTA)); +} diff --git a/packages/hashi/sources/core/proposal/types/update_config.move b/packages/hashi/sources/core/proposal/types/update_config.move index 1282ced58..8f54145c4 100644 --- a/packages/hashi/sources/core/proposal/types/update_config.move +++ b/packages/hashi/sources/core/proposal/types/update_config.move @@ -33,7 +33,8 @@ public fun execute(hashi: &mut Hashi, proposal_id: ID, clock: &Clock) { let UpdateConfig { key, value } = proposal::execute(hashi, proposal_id, clock); assert!( config::is_valid_core_config_entry(&key, &value) - || hashi::btc_config::is_valid_config_entry(&key, &value), + || hashi::btc_config::is_valid_config_entry(&key, &value) + || hashi::mpc_config::is_valid_config_entry(&key, &value), EInvalidConfigEntry, ); let bytes = *key.as_bytes(); diff --git a/packages/hashi/sources/hashi.move b/packages/hashi/sources/hashi.move index 612dca75b..4393635c5 100644 --- a/packages/hashi/sources/hashi.move +++ b/packages/hashi/sources/hashi.move @@ -44,6 +44,7 @@ fun init(ctx: &mut TxContext) { config: { let mut config = hashi::config::create(); hashi::btc_config::init_defaults(&mut config); + hashi::mpc_config::init_defaults(&mut config); config }, treasury: hashi::treasury::create(ctx), From f8acd4a5e51fc6806e54ad15bfcc01a05eb47d08 Mon Sep 17 00:00:00 2001 From: Zhou Fang Date: Wed, 8 Apr 2026 10:28:21 -0700 Subject: [PATCH 2/3] refactor: rename `allowed_delta` to be `weight_reduction_allowed_delta` --- crates/e2e-tests/src/e2e_flow.rs | 9 ++++--- crates/hashi/src/lib.rs | 4 +-- crates/hashi/src/mpc/mpc_except_signing.rs | 10 +++---- .../hashi/src/mpc/mpc_except_signing_tests.rs | 26 +++++++++---------- crates/hashi/src/onchain/mod.rs | 7 +++-- crates/hashi/src/onchain/types.rs | 10 +++---- crates/internal-tools/src/key_recovery.rs | 4 +-- packages/hashi/sources/core/mpc_config.move | 10 ++++--- 8 files changed, 43 insertions(+), 37 deletions(-) diff --git a/crates/e2e-tests/src/e2e_flow.rs b/crates/e2e-tests/src/e2e_flow.rs index 2e12d052d..6d04d9b1f 100644 --- a/crates/e2e-tests/src/e2e_flow.rs +++ b/crates/e2e-tests/src/e2e_flow.rs @@ -1323,20 +1323,21 @@ mod tests { .wait_for_mpc_key(Duration::from_secs(60)) .await?; - use hashi::onchain::types::DEFAULT_MPC_ALLOWED_DELTA; use hashi::onchain::types::DEFAULT_MPC_THRESHOLD_BASIS_POINTS; + use hashi::onchain::types::DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA; let hashi = networks.hashi_network.nodes()[0].hashi(); let threshold_bps = hashi.onchain_state().mpc_threshold_basis_points(); - let allowed_delta = hashi.onchain_state().mpc_allowed_delta(); + let weight_reduction_allowed_delta = + hashi.onchain_state().mpc_weight_reduction_allowed_delta(); assert_eq!( threshold_bps, DEFAULT_MPC_THRESHOLD_BASIS_POINTS, "on-chain mpc_threshold_basis_points ({threshold_bps}) != Rust default ({DEFAULT_MPC_THRESHOLD_BASIS_POINTS})" ); assert_eq!( - allowed_delta, DEFAULT_MPC_ALLOWED_DELTA, - "on-chain mpc_allowed_delta ({allowed_delta}) != Rust default ({DEFAULT_MPC_ALLOWED_DELTA})" + weight_reduction_allowed_delta, DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA, + "on-chain mpc_weight_reduction_allowed_delta ({weight_reduction_allowed_delta}) != Rust default ({DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA})" ); Ok(()) } diff --git a/crates/hashi/src/lib.rs b/crates/hashi/src/lib.rs index 8db089cd5..522e25db2 100644 --- a/crates/hashi/src/lib.rs +++ b/crates/hashi/src/lib.rs @@ -220,7 +220,7 @@ impl Hashi { let hashi = state.hashi(); let committee_set = &hashi.committees; let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); - let allowed_delta = hashi.config.mpc_allowed_delta(); + let weight_reduction_allowed_delta = hashi.config.mpc_weight_reduction_allowed_delta(); let session_id = mpc::SessionId::new(self.config.sui_chain_id(), epoch, &protocol_type); let encryption_key = self.config.encryption_private_key()?; self.db @@ -262,7 +262,7 @@ impl Hashi { signing_key, store, threshold_basis_points, - allowed_delta, + weight_reduction_allowed_delta, chain_id, self.config.test_weight_divisor, batch_size_per_weight, diff --git a/crates/hashi/src/mpc/mpc_except_signing.rs b/crates/hashi/src/mpc/mpc_except_signing.rs index 63c17c616..2bb4fdc17 100644 --- a/crates/hashi/src/mpc/mpc_except_signing.rs +++ b/crates/hashi/src/mpc/mpc_except_signing.rs @@ -122,7 +122,7 @@ impl MpcManager { signing_key: Bls12381PrivateKey, public_message_store: Box, threshold_basis_points: u16, - allowed_delta: u16, + weight_reduction_allowed_delta: u16, chain_id: &str, weight_divisor: Option, batch_size_per_weight: u16, @@ -146,7 +146,7 @@ impl MpcManager { let (nodes, threshold) = build_reduced_nodes( &committee, threshold_basis_points, - allowed_delta, + weight_reduction_allowed_delta, weight_divisor, )?; let total_weight = nodes.total_weight(); @@ -205,7 +205,7 @@ impl MpcManager { let (nodes, threshold) = build_reduced_nodes( prev_committee, threshold_basis_points, - allowed_delta, + weight_reduction_allowed_delta, weight_divisor, )?; (Some(nodes), Some(threshold)) @@ -3592,7 +3592,7 @@ fn compute_messages_hash(messages: &Messages) -> MessageHash { fn build_reduced_nodes( committee: &Committee, threshold_basis_points: u16, - allowed_delta: u16, + weight_reduction_allowed_delta: u16, test_weight_divisor: u16, ) -> MpcResult<(Nodes, u16)> { let nodes_vec: Vec> = committee @@ -3608,7 +3608,7 @@ fn build_reduced_nodes( let total_weight: u16 = nodes_vec.iter().map(|n| n.weight).sum(); let threshold = (total_weight as u32 * threshold_basis_points as u32).div_ceil(MAX_BASIS_POINTS) as u16; - Nodes::new_reduced(nodes_vec, threshold, allowed_delta, 1) + Nodes::new_reduced(nodes_vec, threshold, weight_reduction_allowed_delta, 1) .map_err(|e| MpcError::CryptoError(e.to_string())) } diff --git a/crates/hashi/src/mpc/mpc_except_signing_tests.rs b/crates/hashi/src/mpc/mpc_except_signing_tests.rs index cffc77ad2..90ccabaa3 100644 --- a/crates/hashi/src/mpc/mpc_except_signing_tests.rs +++ b/crates/hashi/src/mpc/mpc_except_signing_tests.rs @@ -25,8 +25,8 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; const TEST_THRESHOLD_BASIS_POINTS: u16 = 3333; -/// Use 0 for allowed_delta in tests to disable weight reduction. -const TEST_ALLOWED_DELTA: u16 = 0; +/// Use 0 for weight_reduction_allowed_delta in tests to disable weight reduction. +const TEST_WEIGHT_REDUCTION_ALLOWED_DELTA: u16 = 0; /// Use 1 for test_weight_divisor in unit tests (they already use small weights). const TEST_WEIGHT_DIVISOR: u16 = 1; const TEST_CHAIN_ID: &str = "testchain"; @@ -289,7 +289,7 @@ impl TestSetup { self.signing_keys[validator_index].clone(), store, TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -903,7 +903,7 @@ fn test_mpc_manager_new_from_committee_set() { signing_key, Box::new(MockPublicMessagesStore), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -967,7 +967,7 @@ fn test_mpc_manager_new_fails_if_no_committee_for_epoch() { signing_keys[0].clone(), Box::new(MockPublicMessagesStore), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, "test", None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -4960,7 +4960,7 @@ impl RotationTestSetup { let (nodes, threshold) = build_reduced_nodes( committee, TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR, ) .unwrap(); @@ -4986,7 +4986,7 @@ impl RotationTestSetup { let (nodes, threshold) = build_reduced_nodes( prev, TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR, ) .unwrap(); @@ -6134,7 +6134,7 @@ async fn test_prepare_previous_output_for_new_member() { new_member_signing_key, Box::new(InMemoryPublicMessagesStore::new()), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -7275,7 +7275,7 @@ fn test_reconstruct_from_dkg_certificates_with_shifted_party_ids() { rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -7438,7 +7438,7 @@ fn test_reconstruct_from_dkg_certificates_stops_at_threshold() { setup.signing_keys[target_index].clone(), Box::new(store), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -7519,7 +7519,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.signing_keys[dealer_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -7551,7 +7551,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.signing_keys[other_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, @@ -7639,7 +7639,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), TEST_THRESHOLD_BASIS_POINTS, - TEST_ALLOWED_DELTA, + TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, TEST_BATCH_SIZE_PER_WEIGHT, diff --git a/crates/hashi/src/onchain/mod.rs b/crates/hashi/src/onchain/mod.rs index 923e92137..fd4407a20 100644 --- a/crates/hashi/src/onchain/mod.rs +++ b/crates/hashi/src/onchain/mod.rs @@ -398,8 +398,11 @@ impl OnchainState { self.state().hashi().config.mpc_threshold_basis_points() } - pub fn mpc_allowed_delta(&self) -> u16 { - self.state().hashi().config.mpc_allowed_delta() + pub fn mpc_weight_reduction_allowed_delta(&self) -> u16 { + self.state() + .hashi() + .config + .mpc_weight_reduction_allowed_delta() } pub fn bridge_service_client( diff --git a/crates/hashi/src/onchain/types.rs b/crates/hashi/src/onchain/types.rs index 8c58fab99..529bc2341 100644 --- a/crates/hashi/src/onchain/types.rs +++ b/crates/hashi/src/onchain/types.rs @@ -471,7 +471,7 @@ const DUST_RELAY_MIN_VALUE: u64 = 546; // These mirror the defaults in mpc_config.move and must be kept in sync. pub const DEFAULT_MPC_THRESHOLD_BASIS_POINTS: u16 = 3333; -pub const DEFAULT_MPC_ALLOWED_DELTA: u16 = 800; +pub const DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA: u16 = 800; impl Config { /// Minimum deposit amount, mirroring the floor logic in btc_config.move. @@ -524,12 +524,12 @@ impl Config { } } - pub fn mpc_allowed_delta(&self) -> u16 { - match self.config.get("mpc_allowed_delta") { + pub fn mpc_weight_reduction_allowed_delta(&self) -> u16 { + match self.config.get("mpc_weight_reduction_allowed_delta") { Some(ConfigValue::U64(v)) => { - u16::try_from(*v).expect("mpc_allowed_delta exceeds u16::MAX") + u16::try_from(*v).expect("mpc_weight_reduction_allowed_delta exceeds u16::MAX") } - _ => DEFAULT_MPC_ALLOWED_DELTA, + _ => DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA, } } } diff --git a/crates/internal-tools/src/key_recovery.rs b/crates/internal-tools/src/key_recovery.rs index 190c33069..d1f7448b2 100644 --- a/crates/internal-tools/src/key_recovery.rs +++ b/crates/internal-tools/src/key_recovery.rs @@ -115,7 +115,7 @@ pub async fn run(args: Args, onchain_state: &OnchainState, chain_id: &str) -> an let state = onchain_state.state(); let hashi = state.hashi(); let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); - let allowed_delta = hashi.config.mpc_allowed_delta(); + let weight_reduction_allowed_delta = hashi.config.mpc_weight_reduction_allowed_delta(); MpcManager::new( validator_address, &hashi.committees, @@ -124,7 +124,7 @@ pub async fn run(args: Args, onchain_state: &OnchainState, chain_id: &str) -> an dummy_signing_key.clone(), Box::new(store), threshold_basis_points, - allowed_delta, + weight_reduction_allowed_delta, chain_id, None, // weight_divisor 0, // batch_size_per_weight (unused for reconstruction) diff --git a/packages/hashi/sources/core/mpc_config.move b/packages/hashi/sources/core/mpc_config.move index d2c86f310..480e8d0ef 100644 --- a/packages/hashi/sources/core/mpc_config.move +++ b/packages/hashi/sources/core/mpc_config.move @@ -9,8 +9,7 @@ const DEFAULT_THRESHOLD_BASIS_POINTS: u64 = 3333; const MAX_BPS: u64 = 10000; -/// Default allowed delta for weight reduction. -const DEFAULT_ALLOWED_DELTA: u64 = 800; +const DEFAULT_WEIGHT_REDUCTION_ALLOWED_DELTA: u64 = 800; #[allow(implicit_const_copy)] public(package) fun is_valid_config_entry( @@ -20,7 +19,7 @@ public(package) fun is_valid_config_entry( let k = key.as_bytes(); if (k == &b"mpc_threshold_basis_points") { value.is_u64() && (*value).as_u64() > 0 && (*value).as_u64() <= MAX_BPS - } else if (k == &b"mpc_allowed_delta") { + } else if (k == &b"mpc_weight_reduction_allowed_delta") { value.is_u64() && (*value).as_u64() <= MAX_BPS } else { false @@ -32,5 +31,8 @@ public(package) fun init_defaults(config: &mut Config) { b"mpc_threshold_basis_points", config_value::new_u64(DEFAULT_THRESHOLD_BASIS_POINTS), ); - config.upsert(b"mpc_allowed_delta", config_value::new_u64(DEFAULT_ALLOWED_DELTA)); + config.upsert( + b"mpc_weight_reduction_allowed_delta", + config_value::new_u64(DEFAULT_WEIGHT_REDUCTION_ALLOWED_DELTA), + ); } From dfe42fc48d751e18fcbc9d4bbf2913c8d8bf79de Mon Sep 17 00:00:00 2001 From: Zhou Fang Date: Tue, 14 Apr 2026 15:05:06 -0700 Subject: [PATCH 3/3] refactor: rename --- crates/e2e-tests/src/e2e_flow.rs | 8 +++---- crates/hashi/src/lib.rs | 4 ++-- crates/hashi/src/mpc/mpc_except_signing.rs | 10 ++++---- .../hashi/src/mpc/mpc_except_signing_tests.rs | 24 +++++++++---------- crates/hashi/src/onchain/mod.rs | 4 ++-- crates/hashi/src/onchain/types.rs | 10 ++++---- crates/internal-tools/src/key_recovery.rs | 4 ++-- packages/hashi/sources/core/mpc_config.move | 8 +++---- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/crates/e2e-tests/src/e2e_flow.rs b/crates/e2e-tests/src/e2e_flow.rs index 6d04d9b1f..0b77a697c 100644 --- a/crates/e2e-tests/src/e2e_flow.rs +++ b/crates/e2e-tests/src/e2e_flow.rs @@ -1323,17 +1323,17 @@ mod tests { .wait_for_mpc_key(Duration::from_secs(60)) .await?; - use hashi::onchain::types::DEFAULT_MPC_THRESHOLD_BASIS_POINTS; + use hashi::onchain::types::DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS; use hashi::onchain::types::DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA; let hashi = networks.hashi_network.nodes()[0].hashi(); - let threshold_bps = hashi.onchain_state().mpc_threshold_basis_points(); + let threshold_bps = hashi.onchain_state().mpc_threshold_in_basis_points(); let weight_reduction_allowed_delta = hashi.onchain_state().mpc_weight_reduction_allowed_delta(); assert_eq!( - threshold_bps, DEFAULT_MPC_THRESHOLD_BASIS_POINTS, - "on-chain mpc_threshold_basis_points ({threshold_bps}) != Rust default ({DEFAULT_MPC_THRESHOLD_BASIS_POINTS})" + threshold_bps, DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS, + "on-chain mpc_threshold_in_basis_points ({threshold_bps}) != Rust default ({DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS})" ); assert_eq!( weight_reduction_allowed_delta, DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA, diff --git a/crates/hashi/src/lib.rs b/crates/hashi/src/lib.rs index 522e25db2..827b403c9 100644 --- a/crates/hashi/src/lib.rs +++ b/crates/hashi/src/lib.rs @@ -219,7 +219,7 @@ impl Hashi { let state = self.onchain_state().state(); let hashi = state.hashi(); let committee_set = &hashi.committees; - let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); + let threshold_in_basis_points = hashi.config.mpc_threshold_in_basis_points(); let weight_reduction_allowed_delta = hashi.config.mpc_weight_reduction_allowed_delta(); let session_id = mpc::SessionId::new(self.config.sui_chain_id(), epoch, &protocol_type); let encryption_key = self.config.encryption_private_key()?; @@ -261,7 +261,7 @@ impl Hashi { encryption_key, signing_key, store, - threshold_basis_points, + threshold_in_basis_points, weight_reduction_allowed_delta, chain_id, self.config.test_weight_divisor, diff --git a/crates/hashi/src/mpc/mpc_except_signing.rs b/crates/hashi/src/mpc/mpc_except_signing.rs index 2bb4fdc17..c8377c2e7 100644 --- a/crates/hashi/src/mpc/mpc_except_signing.rs +++ b/crates/hashi/src/mpc/mpc_except_signing.rs @@ -121,7 +121,7 @@ impl MpcManager { encryption_key: PrivateKey, signing_key: Bls12381PrivateKey, public_message_store: Box, - threshold_basis_points: u16, + threshold_in_basis_points: u16, weight_reduction_allowed_delta: u16, chain_id: &str, weight_divisor: Option, @@ -145,7 +145,7 @@ impl MpcManager { .clone(); let (nodes, threshold) = build_reduced_nodes( &committee, - threshold_basis_points, + threshold_in_basis_points, weight_reduction_allowed_delta, weight_divisor, )?; @@ -204,7 +204,7 @@ impl MpcManager { Some(prev_committee) => { let (nodes, threshold) = build_reduced_nodes( prev_committee, - threshold_basis_points, + threshold_in_basis_points, weight_reduction_allowed_delta, weight_divisor, )?; @@ -3591,7 +3591,7 @@ fn compute_messages_hash(messages: &Messages) -> MessageHash { fn build_reduced_nodes( committee: &Committee, - threshold_basis_points: u16, + threshold_in_basis_points: u16, weight_reduction_allowed_delta: u16, test_weight_divisor: u16, ) -> MpcResult<(Nodes, u16)> { @@ -3607,7 +3607,7 @@ fn build_reduced_nodes( .collect(); let total_weight: u16 = nodes_vec.iter().map(|n| n.weight).sum(); let threshold = - (total_weight as u32 * threshold_basis_points as u32).div_ceil(MAX_BASIS_POINTS) as u16; + (total_weight as u32 * threshold_in_basis_points as u32).div_ceil(MAX_BASIS_POINTS) as u16; Nodes::new_reduced(nodes_vec, threshold, weight_reduction_allowed_delta, 1) .map_err(|e| MpcError::CryptoError(e.to_string())) } diff --git a/crates/hashi/src/mpc/mpc_except_signing_tests.rs b/crates/hashi/src/mpc/mpc_except_signing_tests.rs index 90ccabaa3..a32aaf573 100644 --- a/crates/hashi/src/mpc/mpc_except_signing_tests.rs +++ b/crates/hashi/src/mpc/mpc_except_signing_tests.rs @@ -24,7 +24,7 @@ use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -const TEST_THRESHOLD_BASIS_POINTS: u16 = 3333; +const TEST_THRESHOLD_IN_BASIS_POINTS: u16 = 3333; /// Use 0 for weight_reduction_allowed_delta in tests to disable weight reduction. const TEST_WEIGHT_REDUCTION_ALLOWED_DELTA: u16 = 0; /// Use 1 for test_weight_divisor in unit tests (they already use small weights). @@ -288,7 +288,7 @@ impl TestSetup { self.encryption_keys[validator_index].clone(), self.signing_keys[validator_index].clone(), store, - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -902,7 +902,7 @@ fn test_mpc_manager_new_from_committee_set() { encryption_key, signing_key, Box::new(MockPublicMessagesStore), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -966,7 +966,7 @@ fn test_mpc_manager_new_fails_if_no_committee_for_epoch() { encryption_keys[0].clone(), signing_keys[0].clone(), Box::new(MockPublicMessagesStore), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, "test", None, @@ -4959,7 +4959,7 @@ impl RotationTestSetup { let committee = self.setup.committee(); let (nodes, threshold) = build_reduced_nodes( committee, - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR, ) @@ -4985,7 +4985,7 @@ impl RotationTestSetup { if let Some(ref prev) = previous_committee { let (nodes, threshold) = build_reduced_nodes( prev, - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_WEIGHT_DIVISOR, ) @@ -6133,7 +6133,7 @@ async fn test_prepare_previous_output_for_new_member() { new_member_encryption_key, new_member_signing_key, Box::new(InMemoryPublicMessagesStore::new()), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7274,7 +7274,7 @@ fn test_reconstruct_from_dkg_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[shifted_member_index].clone(), rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7437,7 +7437,7 @@ fn test_reconstruct_from_dkg_certificates_stops_at_threshold() { setup.encryption_keys[target_index].clone(), setup.signing_keys[target_index].clone(), Box::new(store), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7518,7 +7518,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[dealer_idx].clone(), rotation_setup.setup.signing_keys[dealer_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7550,7 +7550,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[other_idx].clone(), rotation_setup.setup.signing_keys[other_idx].clone(), Box::new(InMemoryPublicMessagesStore::new()), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, @@ -7638,7 +7638,7 @@ fn test_reconstruct_from_rotation_certificates_with_shifted_party_ids() { rotation_setup.setup.encryption_keys[shifted_member_index].clone(), rotation_setup.setup.signing_keys[shifted_member_index].clone(), Box::new(store), - TEST_THRESHOLD_BASIS_POINTS, + TEST_THRESHOLD_IN_BASIS_POINTS, TEST_WEIGHT_REDUCTION_ALLOWED_DELTA, TEST_CHAIN_ID, None, diff --git a/crates/hashi/src/onchain/mod.rs b/crates/hashi/src/onchain/mod.rs index fd4407a20..f67b5cbaf 100644 --- a/crates/hashi/src/onchain/mod.rs +++ b/crates/hashi/src/onchain/mod.rs @@ -394,8 +394,8 @@ impl OnchainState { self.state().hashi().config.bitcoin_confirmation_threshold() } - pub fn mpc_threshold_basis_points(&self) -> u16 { - self.state().hashi().config.mpc_threshold_basis_points() + pub fn mpc_threshold_in_basis_points(&self) -> u16 { + self.state().hashi().config.mpc_threshold_in_basis_points() } pub fn mpc_weight_reduction_allowed_delta(&self) -> u16 { diff --git a/crates/hashi/src/onchain/types.rs b/crates/hashi/src/onchain/types.rs index 529bc2341..18d5697b0 100644 --- a/crates/hashi/src/onchain/types.rs +++ b/crates/hashi/src/onchain/types.rs @@ -470,7 +470,7 @@ pub struct Config { const DUST_RELAY_MIN_VALUE: u64 = 546; // These mirror the defaults in mpc_config.move and must be kept in sync. -pub const DEFAULT_MPC_THRESHOLD_BASIS_POINTS: u16 = 3333; +pub const DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS: u16 = 3333; pub const DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA: u16 = 800; impl Config { @@ -515,12 +515,12 @@ impl Config { } } - pub fn mpc_threshold_basis_points(&self) -> u16 { - match self.config.get("mpc_threshold_basis_points") { + pub fn mpc_threshold_in_basis_points(&self) -> u16 { + match self.config.get("mpc_threshold_in_basis_points") { Some(ConfigValue::U64(v)) => { - u16::try_from(*v).expect("mpc_threshold_basis_points exceeds u16::MAX") + u16::try_from(*v).expect("mpc_threshold_in_basis_points exceeds u16::MAX") } - _ => DEFAULT_MPC_THRESHOLD_BASIS_POINTS, + _ => DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS, } } diff --git a/crates/internal-tools/src/key_recovery.rs b/crates/internal-tools/src/key_recovery.rs index d1f7448b2..bf9b0ea7a 100644 --- a/crates/internal-tools/src/key_recovery.rs +++ b/crates/internal-tools/src/key_recovery.rs @@ -114,7 +114,7 @@ pub async fn run(args: Args, onchain_state: &OnchainState, chain_id: &str) -> an let mut manager = { let state = onchain_state.state(); let hashi = state.hashi(); - let threshold_basis_points = hashi.config.mpc_threshold_basis_points(); + let threshold_in_basis_points = hashi.config.mpc_threshold_in_basis_points(); let weight_reduction_allowed_delta = hashi.config.mpc_weight_reduction_allowed_delta(); MpcManager::new( validator_address, @@ -123,7 +123,7 @@ pub async fn run(args: Args, onchain_state: &OnchainState, chain_id: &str) -> an encryption_key, dummy_signing_key.clone(), Box::new(store), - threshold_basis_points, + threshold_in_basis_points, weight_reduction_allowed_delta, chain_id, None, // weight_divisor diff --git a/packages/hashi/sources/core/mpc_config.move b/packages/hashi/sources/core/mpc_config.move index 480e8d0ef..6193f3d51 100644 --- a/packages/hashi/sources/core/mpc_config.move +++ b/packages/hashi/sources/core/mpc_config.move @@ -5,7 +5,7 @@ module hashi::mpc_config; use hashi::{config::Config, config_value}; -const DEFAULT_THRESHOLD_BASIS_POINTS: u64 = 3333; +const DEFAULT_THRESHOLD_IN_BASIS_POINTS: u64 = 3333; const MAX_BPS: u64 = 10000; @@ -17,7 +17,7 @@ public(package) fun is_valid_config_entry( value: &config_value::Value, ): bool { let k = key.as_bytes(); - if (k == &b"mpc_threshold_basis_points") { + if (k == &b"mpc_threshold_in_basis_points") { value.is_u64() && (*value).as_u64() > 0 && (*value).as_u64() <= MAX_BPS } else if (k == &b"mpc_weight_reduction_allowed_delta") { value.is_u64() && (*value).as_u64() <= MAX_BPS @@ -28,8 +28,8 @@ public(package) fun is_valid_config_entry( public(package) fun init_defaults(config: &mut Config) { config.upsert( - b"mpc_threshold_basis_points", - config_value::new_u64(DEFAULT_THRESHOLD_BASIS_POINTS), + b"mpc_threshold_in_basis_points", + config_value::new_u64(DEFAULT_THRESHOLD_IN_BASIS_POINTS), ); config.upsert( b"mpc_weight_reduction_allowed_delta",