Skip to content

Commit

Permalink
Add a flag for enabling msm API in Move (on only in devnet) (#16838)
Browse files Browse the repository at this point in the history
## Description 

Add a flag for enabling msm API in Move (on only in devnet).


## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
benr-ml authored Mar 25, 2024
1 parent 0e8bba2 commit 87e0004
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@
"disallow_change_struct_type_params_on_upgrade": false,
"enable_coin_deny_list": false,
"enable_effects_v2": false,
"enable_group_ops_native_function_msm": false,
"enable_group_ops_native_functions": false,
"enable_jwk_consensus_updates": false,
"enable_poseidon": false,
Expand Down
13 changes: 11 additions & 2 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const MAX_PROTOCOL_VERSION: u64 = 42;
// Version 39: Allow skipped epochs for randomness updates.
// Extra version to fix `test_upgrade_compatibility` simtest.
// Version 40:
// Version 41: Enable group operations native functions in testnet and mainnet.
// Version 41: Enable group operations native functions in testnet and mainnet (without msm).
// Version 42: Migrate sui framework and related code to Move 2024
#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -386,6 +386,10 @@ struct FeatureFlags {
#[serde(skip_serializing_if = "is_false")]
enable_group_ops_native_functions: bool,

// Enable native function for msm.
#[serde(skip_serializing_if = "is_false")]
enable_group_ops_native_function_msm: bool,

// Reject functions with mutable Random.
#[serde(skip_serializing_if = "is_false")]
reject_mutable_random_on_entry_functions: bool,
Expand Down Expand Up @@ -1175,6 +1179,10 @@ impl ProtocolConfig {
self.feature_flags.enable_group_ops_native_functions
}

pub fn enable_group_ops_native_function_msm(&self) -> bool {
self.feature_flags.enable_group_ops_native_function_msm
}

pub fn reject_mutable_random_on_entry_functions(&self) -> bool {
self.feature_flags.reject_mutable_random_on_entry_functions
}
Expand Down Expand Up @@ -1905,6 +1913,7 @@ impl ProtocolConfig {
// Only enable group ops on devnet
if chain != Chain::Mainnet && chain != Chain::Testnet {
cfg.feature_flags.enable_group_ops_native_functions = true;
cfg.feature_flags.enable_group_ops_native_function_msm = true;
// Next values are arbitrary in a similar way as the other crypto native functions.
cfg.group_ops_bls12381_decode_scalar_cost = Some(52);
cfg.group_ops_bls12381_decode_g1_cost = Some(52);
Expand Down Expand Up @@ -1981,7 +1990,7 @@ impl ProtocolConfig {
}
40 => {}
41 => {
// Enable group ops and all networks
// Enable group ops and all networks (but not msm)
cfg.feature_flags.enable_group_ops_native_functions = true;
// Next values are arbitrary in a similar way as the other crypto native functions.
cfg.group_ops_bls12381_decode_scalar_cost = Some(52);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
max_tx_size_bytes: 131072
max_input_objects: 2048
max_size_written_objects: 5000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ feature_flags:
enable_poseidon: true
enable_coin_deny_list: true
enable_group_ops_native_functions: true
enable_group_ops_native_function_msm: true
reject_mutable_random_on_entry_functions: true
max_tx_size_bytes: 131072
max_input_objects: 2048
Expand Down
10 changes: 9 additions & 1 deletion sui-execution/latest/sui-move-natives/src/crypto/group_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ fn is_supported(context: &NativeContext) -> bool {
.enable_group_ops_native_functions()
}

fn is_msm_supported(context: &NativeContext) -> bool {
context
.extensions()
.get::<ObjectRuntime>()
.protocol_config
.enable_group_ops_native_function_msm()
}

// Gas related structs and functions.

#[derive(Clone)]
Expand Down Expand Up @@ -639,7 +647,7 @@ pub fn internal_multi_scalar_mul(
debug_assert!(args.len() == 3);

let cost = context.gas_used();
if !is_supported(context) {
if !is_msm_supported(context) {
return Ok(NativeResult::err(cost, NOT_SUPPORTED_ERROR));
}

Expand Down

0 comments on commit 87e0004

Please sign in to comment.