Skip to content

Commit

Permalink
[Move] Gas logic tweaks and cleanups (MystenLabs#20518)
Browse files Browse the repository at this point in the history
## Description 

Cleans up logic in a number of places around gas. 

## Test plan 

Existing tests/CI + manual local testing.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
tzakian authored Dec 5, 2024
1 parent 772ecd9 commit 9e729bf
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 9
task 4, lines 39-41:
//# run Test::M1::delete_n_ids --args 2048 --gas-budget 100000000000000
mutated: object(0,0)
gas summary: computation_cost: 5000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 19000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5, lines 42-44:
//# run Test::M1::delete_n_ids --args 2049 --gas-budget 100000000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ task 3, lines 59-61:
//# run Test::M1::emit_n_small_events --args 1024 --gas-budget 100000000000000 --summarize
events: 50
mutated: 1
gas summary: computation_cost: 3000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 53000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4, lines 62-64:
//# run Test::M1::emit_n_small_events --args 1025 --gas-budget 100000000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 9
task 4, lines 40-42:
//# run Test::M1::create_n_ids --args 2048 --gas-budget 100000000000000
mutated: object(0,0)
gas summary: computation_cost: 5000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 19000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5, lines 43-45:
//# run Test::M1::create_n_ids --args 2049 --gas-budget 100000000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ task 3, line 30:
//# run a::m::add_n_items --sender A --args 1000 --gas-budget 1000000000000 --summarize
created: 2000
mutated: 1
gas summary: computation_cost: 7000000, storage_cost: 2691388000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 198000000, storage_cost: 2691388000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4, line 32:
//# run a::m::add_n_items --sender A --args 1025 --gas-budget 1000000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ task 4, lines 39-41:
//# run Test::M1::transfer_n_ids --args 2048 --gas-budget 100000000000000 --summarize
created: 2048
mutated: 1
gas summary: computation_cost: 4000000, storage_cost: 2522485600, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 17000000, storage_cost: 2522485600, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5, lines 42-44:
//# run Test::M1::transfer_n_ids --args 2049 --gas-budget 100000000000000
Expand Down
1 change: 1 addition & 0 deletions crates/sui-framework-tests/tests/move_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) fn tests(path: &Path) -> datatest_stable::Result<()> {
config.config.lint_flag = LintFlag::LEVEL_DEFAULT;

let move_config = config.config.clone();
// TODO: Remove this when we support per-test gas limits.
let mut testing_config = UnitTestingConfig::default_with_bound(Some(3_000_000));
testing_config.filter = std::env::var("FILTER").ok().map(|s| s.to_string());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ module sui::bls12381_tests {
// Sum with random terms
let mut gen = random::new_generator_for_testing();
let mut elements = vector[];
let mut i = 2001;
let mut i = 1201;
while (i > 0) {
let scalar = bls12381::scalar_from_u64(gen.generate_u64());
let element = bls12381::g1_mul(&scalar, &bls12381::g1_generator());
Expand Down
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 @@ -1335,6 +1335,7 @@
"narwhal_certificate_v2": false,
"narwhal_new_leader_election_schedule": false,
"narwhal_versioned_metadata": false,
"native_charging_v2": false,
"no_extraneous_module_bytes": false,
"package_digest_hash_module": false,
"package_upgrades": true,
Expand Down
84 changes: 84 additions & 0 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const MAX_PROTOCOL_VERSION: u64 = 70;
// Enable smart ancestor selection in devnet.
// Enable G1Uncompressed group in testnet.
// Version 70: Enable probing for accepted rounds in round prober.
// Add new gas model version to update charging of native functions.

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -576,6 +577,10 @@ struct FeatureFlags {
// Probe accepted rounds in round prober.
#[serde(skip_serializing_if = "is_false")]
consensus_round_prober_probe_accepted_rounds: bool,

// Enable v2 native charging for natives.
#[serde(skip_serializing_if = "is_false")]
native_charging_v2: bool,
}

fn is_false(b: &bool) -> bool {
Expand Down Expand Up @@ -1701,6 +1706,10 @@ impl ProtocolConfig {
self.feature_flags
.consensus_round_prober_probe_accepted_rounds
}

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

#[cfg(not(msim))]
Expand Down Expand Up @@ -2986,6 +2995,81 @@ impl ProtocolConfig {
cfg.feature_flags
.consensus_round_prober_probe_accepted_rounds = true;
}

cfg.poseidon_bn254_cost_per_block = Some(388);

cfg.gas_model_version = Some(9);
cfg.feature_flags.native_charging_v2 = true;
cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
cfg.ed25519_ed25519_verify_cost_base = Some(1802);

// Manually changed to be "under cost"
cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);

cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
Some(8213);
cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
Some(9484);

cfg.hash_keccak256_cost_base = Some(10);
cfg.hash_blake2b256_cost_base = Some(10);

// group ops
cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
cfg.group_ops_bls12381_decode_gt_cost = Some(3068);

cfg.group_ops_bls12381_scalar_add_cost = Some(10);
cfg.group_ops_bls12381_g1_add_cost = Some(1556);
cfg.group_ops_bls12381_g2_add_cost = Some(3048);
cfg.group_ops_bls12381_gt_add_cost = Some(188);

cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
cfg.group_ops_bls12381_gt_sub_cost = Some(497);

cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
cfg.group_ops_bls12381_gt_mul_cost = Some(27490);

cfg.group_ops_bls12381_scalar_div_cost = Some(91);
cfg.group_ops_bls12381_g1_div_cost = Some(5091);
cfg.group_ops_bls12381_g2_div_cost = Some(9206);
cfg.group_ops_bls12381_gt_div_cost = Some(27804);

cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);

cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);

cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);

cfg.group_ops_bls12381_pairing_cost = Some(26897);
cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);

cfg.validator_validate_metadata_cost_base = Some(20000);
}
// Use this template when making changes:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ feature_flags:
validate_identifier_inputs: true
relocate_event_module: true
disallow_new_modules_in_deps_only_packages: true
native_charging_v2: true
max_tx_size_bytes: 131072
max_input_objects: 2048
max_size_written_objects: 5000000
Expand Down Expand Up @@ -143,7 +144,7 @@ obj_access_cost_mutate_per_byte: 40
obj_access_cost_delete_per_byte: 40
obj_access_cost_verify_per_byte: 200
max_type_to_layout_nodes: 512
gas_model_version: 8
gas_model_version: 9
obj_data_cost_refundable: 100
obj_metadata_cost_non_refundable: 50
storage_rebate_rate: 9900
Expand Down Expand Up @@ -191,94 +192,95 @@ tx_context_derive_id_cost_base: 52
types_is_one_time_witness_cost_base: 52
types_is_one_time_witness_type_tag_cost_per_byte: 2
types_is_one_time_witness_type_cost_per_byte: 2
validator_validate_metadata_cost_base: 52
validator_validate_metadata_cost_base: 20000
validator_validate_metadata_data_cost_per_byte: 2
crypto_invalid_arguments_cost: 100
bls12381_bls12381_min_sig_verify_cost_base: 52
bls12381_bls12381_min_sig_verify_cost_base: 44064
bls12381_bls12381_min_sig_verify_msg_cost_per_byte: 2
bls12381_bls12381_min_sig_verify_msg_cost_per_block: 2
bls12381_bls12381_min_pk_verify_cost_base: 52
bls12381_bls12381_min_pk_verify_cost_base: 49282
bls12381_bls12381_min_pk_verify_msg_cost_per_byte: 2
bls12381_bls12381_min_pk_verify_msg_cost_per_block: 2
ecdsa_k1_ecrecover_keccak256_cost_base: 52
ecdsa_k1_ecrecover_keccak256_cost_base: 500
ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: 2
ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: 2
ecdsa_k1_ecrecover_sha256_cost_base: 52
ecdsa_k1_ecrecover_sha256_cost_base: 500
ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: 2
ecdsa_k1_ecrecover_sha256_msg_cost_per_block: 2
ecdsa_k1_decompress_pubkey_cost_base: 52
ecdsa_k1_secp256k1_verify_keccak256_cost_base: 52
ecdsa_k1_secp256k1_verify_keccak256_cost_base: 1470
ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: 2
ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: 2
ecdsa_k1_secp256k1_verify_sha256_cost_base: 52
ecdsa_k1_secp256k1_verify_sha256_cost_base: 1470
ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: 2
ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: 2
ecdsa_r1_ecrecover_keccak256_cost_base: 52
ecdsa_r1_ecrecover_keccak256_cost_base: 1173
ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: 2
ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: 2
ecdsa_r1_ecrecover_sha256_cost_base: 52
ecdsa_r1_ecrecover_sha256_cost_base: 1173
ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: 2
ecdsa_r1_ecrecover_sha256_msg_cost_per_block: 2
ecdsa_r1_secp256r1_verify_keccak256_cost_base: 52
ecdsa_r1_secp256r1_verify_keccak256_cost_base: 4225
ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: 2
ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: 2
ecdsa_r1_secp256r1_verify_sha256_cost_base: 52
ecdsa_r1_secp256r1_verify_sha256_cost_base: 4225
ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: 2
ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: 2
ecvrf_ecvrf_verify_cost_base: 52
ecvrf_ecvrf_verify_cost_base: 4848
ecvrf_ecvrf_verify_alpha_string_cost_per_byte: 2
ecvrf_ecvrf_verify_alpha_string_cost_per_block: 2
ed25519_ed25519_verify_cost_base: 52
ed25519_ed25519_verify_cost_base: 1802
ed25519_ed25519_verify_msg_cost_per_byte: 2
ed25519_ed25519_verify_msg_cost_per_block: 2
groth16_prepare_verifying_key_bls12381_cost_base: 52
groth16_prepare_verifying_key_bn254_cost_base: 52
groth16_verify_groth16_proof_internal_bls12381_cost_base: 52
groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: 2
groth16_verify_groth16_proof_internal_bn254_cost_base: 52
groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: 2
groth16_prepare_verifying_key_bls12381_cost_base: 53838
groth16_prepare_verifying_key_bn254_cost_base: 82010
groth16_verify_groth16_proof_internal_bls12381_cost_base: 72090
groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: 8213
groth16_verify_groth16_proof_internal_bn254_cost_base: 115502
groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: 9484
groth16_verify_groth16_proof_internal_public_input_cost_per_byte: 2
hash_blake2b256_cost_base: 52
hash_blake2b256_cost_base: 10
hash_blake2b256_data_cost_per_byte: 2
hash_blake2b256_data_cost_per_block: 2
hash_keccak256_cost_base: 52
hash_keccak256_cost_base: 10
hash_keccak256_data_cost_per_byte: 2
hash_keccak256_data_cost_per_block: 2
group_ops_bls12381_decode_scalar_cost: 52
group_ops_bls12381_decode_g1_cost: 52
group_ops_bls12381_decode_g2_cost: 52
group_ops_bls12381_decode_gt_cost: 52
group_ops_bls12381_scalar_add_cost: 52
group_ops_bls12381_g1_add_cost: 52
group_ops_bls12381_g2_add_cost: 52
group_ops_bls12381_gt_add_cost: 52
group_ops_bls12381_scalar_sub_cost: 52
group_ops_bls12381_g1_sub_cost: 52
group_ops_bls12381_g2_sub_cost: 52
group_ops_bls12381_gt_sub_cost: 52
group_ops_bls12381_scalar_mul_cost: 52
group_ops_bls12381_g1_mul_cost: 52
group_ops_bls12381_g2_mul_cost: 52
group_ops_bls12381_gt_mul_cost: 52
group_ops_bls12381_scalar_div_cost: 52
group_ops_bls12381_g1_div_cost: 52
group_ops_bls12381_g2_div_cost: 52
group_ops_bls12381_gt_div_cost: 52
group_ops_bls12381_g1_hash_to_base_cost: 52
group_ops_bls12381_g2_hash_to_base_cost: 52
poseidon_bn254_cost_per_block: 388
group_ops_bls12381_decode_scalar_cost: 7
group_ops_bls12381_decode_g1_cost: 2848
group_ops_bls12381_decode_g2_cost: 3770
group_ops_bls12381_decode_gt_cost: 3068
group_ops_bls12381_scalar_add_cost: 10
group_ops_bls12381_g1_add_cost: 1556
group_ops_bls12381_g2_add_cost: 3048
group_ops_bls12381_gt_add_cost: 188
group_ops_bls12381_scalar_sub_cost: 10
group_ops_bls12381_g1_sub_cost: 1550
group_ops_bls12381_g2_sub_cost: 3019
group_ops_bls12381_gt_sub_cost: 497
group_ops_bls12381_scalar_mul_cost: 11
group_ops_bls12381_g1_mul_cost: 4842
group_ops_bls12381_g2_mul_cost: 9108
group_ops_bls12381_gt_mul_cost: 27490
group_ops_bls12381_scalar_div_cost: 91
group_ops_bls12381_g1_div_cost: 5091
group_ops_bls12381_g2_div_cost: 9206
group_ops_bls12381_gt_div_cost: 27804
group_ops_bls12381_g1_hash_to_base_cost: 2962
group_ops_bls12381_g2_hash_to_base_cost: 8688
group_ops_bls12381_g1_hash_to_cost_per_byte: 2
group_ops_bls12381_g2_hash_to_cost_per_byte: 2
group_ops_bls12381_g1_msm_base_cost: 52
group_ops_bls12381_g2_msm_base_cost: 52
group_ops_bls12381_g1_msm_base_cost_per_input: 52
group_ops_bls12381_g2_msm_base_cost_per_input: 52
group_ops_bls12381_g1_msm_base_cost: 62648
group_ops_bls12381_g2_msm_base_cost: 131192
group_ops_bls12381_g1_msm_base_cost_per_input: 1333
group_ops_bls12381_g2_msm_base_cost_per_input: 3216
group_ops_bls12381_msm_max_len: 32
group_ops_bls12381_pairing_cost: 52
group_ops_bls12381_g1_to_uncompressed_g1_cost: 26
group_ops_bls12381_uncompressed_g1_to_g1_cost: 52
group_ops_bls12381_uncompressed_g1_sum_base_cost: 26
group_ops_bls12381_uncompressed_g1_sum_cost_per_term: 13
group_ops_bls12381_uncompressed_g1_sum_max_terms: 2000
group_ops_bls12381_pairing_cost: 26897
group_ops_bls12381_g1_to_uncompressed_g1_cost: 2099
group_ops_bls12381_uncompressed_g1_to_g1_cost: 677
group_ops_bls12381_uncompressed_g1_sum_base_cost: 77
group_ops_bls12381_uncompressed_g1_sum_cost_per_term: 26
group_ops_bls12381_uncompressed_g1_sum_max_terms: 1200
hmac_hmac_sha3_256_cost_base: 52
hmac_hmac_sha3_256_input_cost_per_byte: 2
hmac_hmac_sha3_256_input_cost_per_block: 2
Expand Down
Loading

0 comments on commit 9e729bf

Please sign in to comment.