diff --git a/crates/iota-adapter-transactional-tests/tests/size_limits/deleted_id_limits_tests.exp b/crates/iota-adapter-transactional-tests/tests/size_limits/deleted_id_limits_tests.exp index 44c93bb50c2..6ab19645018 100644 --- a/crates/iota-adapter-transactional-tests/tests/size_limits/deleted_id_limits_tests.exp +++ b/crates/iota-adapter-transactional-tests/tests/size_limits/deleted_id_limits_tests.exp @@ -19,7 +19,7 @@ gas summary: computation_cost: 1000000, computation_cost_burned: 1000000, storag task 4, lines 40-42: //# run Test::M1::delete_n_ids --args 2048 --gas-budget 100000000000000 mutated: object(0,0) -gas summary: computation_cost: 5000000, computation_cost_burned: 5000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 +gas summary: computation_cost: 19000000, computation_cost_burned: 19000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 task 5, lines 43-45: //# run Test::M1::delete_n_ids --args 2049 --gas-budget 100000000000000 diff --git a/crates/iota-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp b/crates/iota-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp index 2891692ba6e..453ea3719b5 100644 --- a/crates/iota-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp +++ b/crates/iota-adapter-transactional-tests/tests/size_limits/event_limits_tests.exp @@ -16,7 +16,7 @@ task 3, lines 60-62: //# run Test::M1::emit_n_small_events --args 1024 --gas-budget 100000000000000 --summarize events: 50 mutated: 1 -gas summary: computation_cost: 3000000, computation_cost_burned: 3000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 +gas summary: computation_cost: 53000000, computation_cost_burned: 53000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 task 4, lines 63-65: //# run Test::M1::emit_n_small_events --args 1025 --gas-budget 100000000000000 diff --git a/crates/iota-adapter-transactional-tests/tests/size_limits/new_id_limits_tests.exp b/crates/iota-adapter-transactional-tests/tests/size_limits/new_id_limits_tests.exp index 4b71e28f78b..ccdcde814de 100644 --- a/crates/iota-adapter-transactional-tests/tests/size_limits/new_id_limits_tests.exp +++ b/crates/iota-adapter-transactional-tests/tests/size_limits/new_id_limits_tests.exp @@ -19,7 +19,7 @@ gas summary: computation_cost: 1000000, computation_cost_burned: 1000000, storag task 4, lines 41-43: //# run Test::M1::create_n_ids --args 2048 --gas-budget 100000000000000 mutated: object(0,0) -gas summary: computation_cost: 5000000, computation_cost_burned: 5000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 +gas summary: computation_cost: 19000000, computation_cost_burned: 19000000, storage_cost: 980400, storage_rebate: 980400, non_refundable_storage_fee: 0 task 5, lines 44-46: //# run Test::M1::create_n_ids --args 2049 --gas-budget 100000000000000 diff --git a/crates/iota-adapter-transactional-tests/tests/size_limits/object_runtime_limits.exp b/crates/iota-adapter-transactional-tests/tests/size_limits/object_runtime_limits.exp index fbe366dfed6..298977f5669 100644 --- a/crates/iota-adapter-transactional-tests/tests/size_limits/object_runtime_limits.exp +++ b/crates/iota-adapter-transactional-tests/tests/size_limits/object_runtime_limits.exp @@ -19,7 +19,7 @@ task 3, line 31: //# run a::m::add_n_items --sender A --args 1000 --gas-budget 1000000000000 --summarize created: 2000 mutated: 1 -gas summary: computation_cost: 7000000, computation_cost_burned: 7000000, storage_cost: 2676180400, storage_rebate: 980400, non_refundable_storage_fee: 0 +gas summary: computation_cost: 198000000, computation_cost_burned: 198000000, storage_cost: 2676180400, storage_rebate: 980400, non_refundable_storage_fee: 0 task 4, line 33: //# run a::m::add_n_items --sender A --args 1025 --gas-budget 1000000000000 diff --git a/crates/iota-adapter-transactional-tests/tests/size_limits/transferred_id_limits_tests.exp b/crates/iota-adapter-transactional-tests/tests/size_limits/transferred_id_limits_tests.exp index 8ac70fe288a..4aa0d9bd056 100644 --- a/crates/iota-adapter-transactional-tests/tests/size_limits/transferred_id_limits_tests.exp +++ b/crates/iota-adapter-transactional-tests/tests/size_limits/transferred_id_limits_tests.exp @@ -22,7 +22,7 @@ task 4, lines 40-42: //# run Test::M1::transfer_n_ids --args 2048 --gas-budget 100000000000000 --summarize created: 2048 mutated: 1 -gas summary: computation_cost: 4000000, computation_cost_burned: 4000000, storage_cost: 2506913200, storage_rebate: 980400, non_refundable_storage_fee: 0 +gas summary: computation_cost: 17000000, computation_cost_burned: 17000000, storage_cost: 2506913200, storage_rebate: 980400, non_refundable_storage_fee: 0 task 5, lines 43-45: //# run Test::M1::transfer_n_ids --args 2049 --gas-budget 100000000000000 diff --git a/crates/iota-framework-tests/tests/move_tests.rs b/crates/iota-framework-tests/tests/move_tests.rs index 9b24c4067f7..cd46737e9df 100644 --- a/crates/iota-framework-tests/tests/move_tests.rs +++ b/crates/iota-framework-tests/tests/move_tests.rs @@ -54,6 +54,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()); diff --git a/crates/iota-framework/packages/iota-framework/tests/crypto/bls12381_tests.move b/crates/iota-framework/packages/iota-framework/tests/crypto/bls12381_tests.move index 151665ee6fa..223891c5b7a 100644 --- a/crates/iota-framework/packages/iota-framework/tests/crypto/bls12381_tests.move +++ b/crates/iota-framework/packages/iota-framework/tests/crypto/bls12381_tests.move @@ -436,7 +436,7 @@ module iota::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()); diff --git a/crates/iota-open-rpc/spec/openrpc.json b/crates/iota-open-rpc/spec/openrpc.json index 0510dc42925..b5cedbc52db 100644 --- a/crates/iota-open-rpc/spec/openrpc.json +++ b/crates/iota-open-rpc/spec/openrpc.json @@ -1313,6 +1313,7 @@ "enable_poseidon": true, "enable_vdf": true, "hardened_otw_check": true, + "native_charging_v2": false, "no_extraneous_module_bytes": true, "passkey_auth": true, "relocate_event_module": false, diff --git a/crates/iota-protocol-config/src/lib.rs b/crates/iota-protocol-config/src/lib.rs index 61f744302b9..6e5d70069d5 100644 --- a/crates/iota-protocol-config/src/lib.rs +++ b/crates/iota-protocol-config/src/lib.rs @@ -23,15 +23,17 @@ pub const MAX_PROTOCOL_VERSION: u64 = 5; // // Version 1: Original version. // Version 2: Don't redistribute slashed staking rewards, fix computation of -// SystemEpochInfoEventV1. +// SystemEpochInfoEventV1. // Version 3: Set the `relocate_event_module` to be true so that the module that -// is associated as the "sending module" for an event is relocated by linkage. -// Add `Clock` based unlock to `Timelock` objects. +// is associated as the "sending module" for an event is relocated by +// linkage. +// Add `Clock` based unlock to `Timelock` objects. // Version 4: Introduce the `max_type_to_layout_nodes` config that sets the -// maximal nodes which are allowed when converting to a type layout. -// Version 5: Disallow adding new modules in `deps-only` packages. Enable proper -// conversion of certain type argument errors in the execution layer using the -// `convert_type_argument_error` function, which is now used in all cases. +// maximal nodes which are allowed when converting to a type layout. +// Version 5: Disallow adding new modules in `deps-only` packages. +// Add new gas model version to update charging of native functions. +// Enable proper conversion of certain type argument errors in the +// execution layer. #[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct ProtocolVersion(u64); @@ -205,6 +207,10 @@ struct FeatureFlags { #[serde(skip_serializing_if = "is_false")] disallow_new_modules_in_deps_only_packages: bool, + // Enable v2 native charging for natives. + #[serde(skip_serializing_if = "is_false")] + native_charging_v2: bool, + // Properly convert certain type argument errors in the execution layer. #[serde(skip_serializing_if = "is_false")] convert_type_argument_error: bool, @@ -1110,6 +1116,10 @@ impl ProtocolConfig { self.feature_flags .disallow_new_modules_in_deps_only_packages } + + pub fn native_charging_v2(&self) -> bool { + self.feature_flags.native_charging_v2 + } } #[cfg(not(msim))] @@ -1715,15 +1725,86 @@ impl ProtocolConfig { 5 => { cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true; cfg.feature_flags.convert_type_argument_error = true; - cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(26); - cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(52); - cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(26); - cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(13); - cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(2000); + cfg.feature_flags.native_charging_v2 = true; if chain != Chain::Mainnet && chain != Chain::Testnet { cfg.feature_flags.uncompressed_g1_group_elements = true; } + + cfg.gas_model_version = Some(2); + + cfg.poseidon_bn254_cost_per_block = Some(388); + + 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_uncompressed_g1_sum_max_terms = Some(1200); + + cfg.group_ops_bls12381_pairing_cost = Some(26897); + + cfg.validator_validate_metadata_cost_base = Some(20000); } // Use this template when making changes: // diff --git a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Mainnet_version_5.snap b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Mainnet_version_5.snap index e7d282ae429..04cbab54fe1 100644 --- a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Mainnet_version_5.snap +++ b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Mainnet_version_5.snap @@ -9,6 +9,7 @@ feature_flags: zklogin_max_epoch_upper_bound_delta: 30 relocate_event_module: true disallow_new_modules_in_deps_only_packages: true + native_charging_v2: true convert_type_argument_error: true max_tx_size_bytes: 131072 max_input_objects: 2048 @@ -88,7 +89,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: 1 +gas_model_version: 2 obj_data_cost_refundable: 100 obj_metadata_cost_non_refundable: 50 storage_rebate_rate: 10000 @@ -136,94 +137,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 diff --git a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Testnet_version_5.snap b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Testnet_version_5.snap index 6267ee8ce93..70903247ec0 100644 --- a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Testnet_version_5.snap +++ b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__Testnet_version_5.snap @@ -9,6 +9,7 @@ feature_flags: zklogin_max_epoch_upper_bound_delta: 30 relocate_event_module: true disallow_new_modules_in_deps_only_packages: true + native_charging_v2: true convert_type_argument_error: true max_tx_size_bytes: 131072 max_input_objects: 2048 @@ -88,7 +89,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: 1 +gas_model_version: 2 obj_data_cost_refundable: 100 obj_metadata_cost_non_refundable: 50 storage_rebate_rate: 10000 @@ -136,94 +137,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 diff --git a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__version_5.snap b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__version_5.snap index 1b7daffd76a..fc337bc2806 100644 --- a/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__version_5.snap +++ b/crates/iota-protocol-config/src/snapshots/iota_protocol_config__test__version_5.snap @@ -14,6 +14,7 @@ feature_flags: relocate_event_module: true uncompressed_g1_group_elements: true disallow_new_modules_in_deps_only_packages: true + native_charging_v2: true convert_type_argument_error: true max_tx_size_bytes: 131072 max_input_objects: 2048 @@ -93,7 +94,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: 1 +gas_model_version: 2 obj_data_cost_refundable: 100 obj_metadata_cost_non_refundable: 50 storage_rebate_rate: 10000 @@ -141,96 +142,96 @@ 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 poseidon_bn254_cost_base: 260 -poseidon_bn254_cost_per_block: 10 -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 diff --git a/crates/iota-types/src/gas_model/gas_predicates.rs b/crates/iota-types/src/gas_model/gas_predicates.rs index 9dbbe50c16a..a8af0c21df7 100644 --- a/crates/iota-types/src/gas_model/gas_predicates.rs +++ b/crates/iota-types/src/gas_model/gas_predicates.rs @@ -8,6 +8,19 @@ use crate::gas_model::{tables::initial_cost_schedule_v1, units_types::CostTable}; +// Threshold after which native functions contribute to virtual instruction +// count. +const V2_NATIVE_FUNCTION_CALL_THRESHOLD: u64 = 700; + +// Return if the native function call threshold is exceeded +pub fn native_function_threshold_exceeded(gas_model_version: u64, num_native_calls: u64) -> bool { + if gas_model_version > 1 { + num_native_calls > V2_NATIVE_FUNCTION_CALL_THRESHOLD + } else { + false + } +} + // Return the version supported cost table pub fn cost_table_for_version(_gas_model: u64) -> CostTable { initial_cost_schedule_v1() diff --git a/crates/iota-types/src/gas_model/tables.rs b/crates/iota-types/src/gas_model/tables.rs index bb6360f6526..37cd5cea91e 100644 --- a/crates/iota-types/src/gas_model/tables.rs +++ b/crates/iota-types/src/gas_model/tables.rs @@ -18,6 +18,7 @@ use move_vm_types::{ }; use once_cell::sync::Lazy; +use super::gas_predicates::native_function_threshold_exceeded; use crate::gas_model::units_types::{CostTable, Gas, GasCost}; /// VM flat fee @@ -76,6 +77,7 @@ pub struct GasStatus { instructions_current_tier_mult: u64, profiler: Option, + num_native_calls: u64, } impl GasStatus { @@ -113,6 +115,7 @@ impl GasStatus { stack_size_next_tier_start, instructions_next_tier_start, profiler: None, + num_native_calls: 0, } } @@ -140,6 +143,7 @@ impl GasStatus { stack_size_next_tier_start: None, instructions_next_tier_start: None, profiler: None, + num_native_calls: 0, } } @@ -423,12 +427,24 @@ impl GasMeter for GasStatus { }) }) .unwrap_or_else(AbstractMemorySize::zero); - // Charge for the stack operations. We don't count this as an "instruction" - // since we already accounted for the `Call` instruction in the - // `charge_native_function_before_execution` call. - self.charge(0, pushes, 0, size_increase.into(), 0)?; - // Now charge the gas that the native function told us to charge. - self.deduct_gas(amount) + self.num_native_calls = self.num_native_calls.saturating_add(1); + if native_function_threshold_exceeded(self.gas_model_version, self.num_native_calls) { + // Charge for the stack operations. We don't count this as an "instruction" + // since we already accounted for the `Call` instruction in the + // `charge_native_function_before_execution` call. + // The amount returned by the native function is viewed as the "virtual" + // instruction cost for the native function, and will be charged and + // contribute to the overall cost tier of the transaction + // accordingly. + self.charge(amount.into(), pushes, 0, size_increase.into(), 0) + } else { + // Charge for the stack operations. We don't count this as an "instruction" + // since we already accounted for the `Call` instruction in the + // `charge_native_function_before_execution` call. + self.charge(0, pushes, 0, size_increase.into(), 0)?; + // Now charge the gas that the native function told us to charge. + self.deduct_gas(amount) + } } fn charge_native_function_before_execution( diff --git a/iota-execution/latest/iota-move-natives/src/crypto/groth16.rs b/iota-execution/latest/iota-move-natives/src/crypto/groth16.rs index 4f590597225..6e53f70ce40 100644 --- a/iota-execution/latest/iota-move-natives/src/crypto/groth16.rs +++ b/iota-execution/latest/iota-move-natives/src/crypto/groth16.rs @@ -15,7 +15,7 @@ use move_vm_types::{ }; use smallvec::smallvec; -use crate::NativesCostTable; +use crate::{NativesCostTable, object_runtime::ObjectRuntime}; pub const INVALID_VERIFYING_KEY: u64 = 0; pub const INVALID_CURVE: u64 = 1; @@ -205,7 +205,17 @@ pub fn verify_groth16_proof_internal( // Charge for failure but dont fail if we run out of gas otherwise the actual // error is masked by OUT_OF_GAS error context.charge_gas(crypto_invalid_arguments_cost); - return Ok(NativeResult::err(context.gas_budget(), INVALID_CURVE)); + let cost = if context + .extensions() + .get::() + .protocol_config + .native_charging_v2() + { + context.gas_used() + } else { + context.gas_budget() + }; + return Ok(NativeResult::err(cost, INVALID_CURVE)); } }; // Charge the base cost for this oper diff --git a/iota-execution/latest/iota-move-natives/src/crypto/group_ops.rs b/iota-execution/latest/iota-move-natives/src/crypto/group_ops.rs index 7ada14f5803..a3a17685786 100644 --- a/iota-execution/latest/iota-move-natives/src/crypto/group_ops.rs +++ b/iota-execution/latest/iota-move-natives/src/crypto/group_ops.rs @@ -37,6 +37,38 @@ fn is_msm_supported(context: &NativeContext) -> bool { .enable_group_ops_native_function_msm() } +fn v2_native_charge(context: &NativeContext, cost: InternalGas) -> InternalGas { + if context + .extensions() + .get::() + .protocol_config + .native_charging_v2() + { + context.gas_used() + } else { + cost + } +} + +fn map_op_result( + context: &NativeContext, + cost: InternalGas, + result: FastCryptoResult>, +) -> PartialVMResult { + match result { + Ok(bytes) => Ok(NativeResult::ok( + v2_native_charge(context, cost), + smallvec![Value::vector_u8(bytes)], + )), + // Since all Element are validated on construction, this error should never happen unless + // the requested type is wrong or inputs are invalid. + Err(_) => Ok(NativeResult::err( + v2_native_charge(context, cost), + INVALID_INPUT_ERROR, + )), + } +} + fn is_uncompressed_g1_supported(context: &NativeContext) -> bool { context .extensions() @@ -44,6 +76,7 @@ fn is_uncompressed_g1_supported(context: &NativeContext) -> bool { .protocol_config .uncompressed_g1_group_elements() } + // Gas related structs and functions. #[derive(Clone)] @@ -219,7 +252,10 @@ pub fn internal_validate( _ => false, }; - Ok(NativeResult::ok(cost, smallvec![Value::bool(result)])) + Ok(NativeResult::ok( + v2_native_charge(context, cost), + smallvec![Value::bool(result)], + )) } /// **************************************************************************** @@ -271,12 +307,7 @@ pub fn internal_add( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong or inputs are invalid. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } /// **************************************************************************** @@ -328,12 +359,7 @@ pub fn internal_sub( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong or inputs are invalid. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } /// **************************************************************************** @@ -400,12 +426,7 @@ pub fn internal_mul( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong or inputs are invalid. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } /// **************************************************************************** @@ -472,12 +493,7 @@ pub fn internal_div( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong, inputs are invalid, or a=0. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } #[rustfmt::skip] @@ -539,12 +555,7 @@ pub fn internal_hash_to( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong or inputs are invalid. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } // Based on calculation from https://github.com/supranational/blst/blob/master/src/multi_scalar.c#L270 @@ -707,7 +718,10 @@ pub fn internal_multi_scalar_mul( scalars.as_ref(), elements.as_ref(), ), - _ => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), + _ => Ok(NativeResult::err( + v2_native_charge(context, cost), + INVALID_INPUT_ERROR, + )), } } @@ -752,12 +766,7 @@ pub fn internal_pairing( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } /// **************************************************************************** @@ -817,12 +826,7 @@ pub fn internal_convert( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - // Since all Element are validated on construction, this error should never happen unless - // the requested type is wrong. - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) } /// **************************************************************************** @@ -905,8 +909,5 @@ pub fn internal_sum( _ => Err(FastCryptoError::InvalidInput), }; - match result { - Ok(bytes) => Ok(NativeResult::ok(cost, smallvec![Value::vector_u8(bytes)])), - Err(_) => Ok(NativeResult::err(cost, INVALID_INPUT_ERROR)), - } + map_op_result(context, cost, result) }