1use self::{
5 address::{AddressFromBytesCostParams, AddressFromU256CostParams, AddressToU256CostParams},
6 config::ConfigReadSettingImplCostParams,
7 crypto::{bls12381, ecdsa_k1, ecdsa_r1, ecvrf, ed25519, groth16, hash, hmac},
8 crypto::{
9 bls12381::{Bls12381Bls12381MinPkVerifyCostParams, Bls12381Bls12381MinSigVerifyCostParams},
10 ecdsa_k1::{
11 EcdsaK1DecompressPubkeyCostParams, EcdsaK1EcrecoverCostParams,
12 EcdsaK1Secp256k1VerifyCostParams,
13 },
14 ecdsa_r1::{EcdsaR1EcrecoverCostParams, EcdsaR1Secp256R1VerifyCostParams},
15 ecvrf::EcvrfEcvrfVerifyCostParams,
16 ed25519::Ed25519VerifyCostParams,
17 groth16::{
18 Groth16PrepareVerifyingKeyCostParams, Groth16VerifyGroth16ProofInternalCostParams,
19 },
20 hash::{HashBlake2b256CostParams, HashKeccak256CostParams},
21 hmac::HmacHmacSha3256CostParams,
22 poseidon,
23 },
24 dynamic_field::{
25 DynamicFieldAddChildObjectCostParams, DynamicFieldBorrowChildObjectCostParams,
26 DynamicFieldHasChildObjectCostParams, DynamicFieldHasChildObjectWithTyCostParams,
27 DynamicFieldHashTypeAndKeyCostParams, DynamicFieldRemoveChildObjectCostParams,
28 },
29 event::EventEmitCostParams,
30 object::{BorrowUidCostParams, DeleteImplCostParams, RecordNewIdCostParams},
31 package::PackageVersioningOriginalPackageIdImplCostParams,
32 scratch::{
33 ScratchAddCostParams, ScratchExistsCostParams, ScratchExistsWithTypeCostParams,
34 ScratchReadCostParams, ScratchRemoveCostParams,
35 },
36 transfer::{
37 TransferFreezeObjectCostParams, TransferInternalCostParams, TransferShareObjectCostParams,
38 },
39 tx_context::{
40 TxContextDeriveIdCostParams, TxContextEpochCostParams, TxContextEpochTimestampMsCostParams,
41 TxContextFreshIdCostParams, TxContextGasBudgetCostParams, TxContextGasPriceCostParams,
42 TxContextIdsCreatedCostParams, TxContextRGPCostParams, TxContextReplaceCostParams,
43 TxContextSenderCostParams, TxContextSponsorCostParams,
44 },
45 types::TypesIsOneTimeWitnessCostParams,
46 validator::ValidatorValidateMetadataBcsCostParams,
47};
48use crate::crypto::group_ops::GroupOpsCostParams;
49use crate::crypto::poseidon::PoseidonBN254CostParams;
50use crate::crypto::rangeproofs::{self, BulletproofsCostParams};
51use crate::crypto::zklogin;
52use crate::crypto::zklogin::{CheckZkloginIdCostParams, CheckZkloginIssuerCostParams};
53use crate::{crypto::group_ops, transfer::PartyTransferInternalCostParams};
54use better_any::{Tid, TidAble};
55use crypto::nitro_attestation::{self, NitroAttestationCostParams};
56use crypto::vdf::{self, VDFCostParams};
57use move_binary_format::errors::{PartialVMError, PartialVMResult};
58use move_binary_format::safe_unwrap;
59use move_core_types::{
60 annotated_value as A,
61 gas_algebra::{AbstractMemorySize, InternalGas},
62 identifier::Identifier,
63 language_storage::{StructTag, TypeTag},
64 runtime_value as R,
65 vm_status::StatusCode,
66};
67use move_vm_runtime::natives::{
68 extensions::NativeExtensionMarker,
69 functions::{NativeContext, NativeFunction, NativeFunctionTable},
70 move_stdlib::{self as MSN, GasParameters},
71};
72use move_vm_runtime::{
73 execution::{
74 Type,
75 values::{Struct, Value},
76 },
77 natives::functions::NativeResult,
78 shared::views::{SizeConfig, ValueView},
79};
80use std::sync::Arc;
81use sui_protocol_config::ProtocolConfig;
82use sui_types::{MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_ADDRESS};
83use transfer::TransferReceiveObjectInternalCostParams;
84
85mod accumulator;
86mod address;
87mod config;
88mod crypto;
89mod dynamic_field;
90pub mod event;
91mod funds_accumulator;
92mod object;
93pub mod object_runtime;
94mod package;
95mod protocol_config;
96mod random;
97pub mod scratch;
98pub mod test_scenario;
99mod test_utils;
100pub mod transaction_context;
101mod transfer;
102mod tx_context;
103mod types;
104mod validator;
105
106const DEFAULT_UNUSED_TX_CONTEXT_ENTRY_COST: u64 = 10;
108#[derive(Tid)]
109pub struct NativesCostTable {
110 pub address_from_bytes_cost_params: AddressFromBytesCostParams,
112 pub address_to_u256_cost_params: AddressToU256CostParams,
113 pub address_from_u256_cost_params: AddressFromU256CostParams,
114
115 pub config_read_setting_impl_cost_params: ConfigReadSettingImplCostParams,
117
118 pub package_original_package_id_impl_cost_params:
120 PackageVersioningOriginalPackageIdImplCostParams,
121
122 pub dynamic_field_hash_type_and_key_cost_params: DynamicFieldHashTypeAndKeyCostParams,
124 pub dynamic_field_add_child_object_cost_params: DynamicFieldAddChildObjectCostParams,
125 pub dynamic_field_borrow_child_object_cost_params: DynamicFieldBorrowChildObjectCostParams,
126 pub dynamic_field_remove_child_object_cost_params: DynamicFieldRemoveChildObjectCostParams,
127 pub dynamic_field_has_child_object_cost_params: DynamicFieldHasChildObjectCostParams,
128 pub dynamic_field_has_child_object_with_ty_cost_params:
129 DynamicFieldHasChildObjectWithTyCostParams,
130
131 pub scratch_add_cost_params: ScratchAddCostParams,
133 pub scratch_read_cost_params: ScratchReadCostParams,
134 pub scratch_remove_cost_params: ScratchRemoveCostParams,
135 pub scratch_exists_cost_params: ScratchExistsCostParams,
136 pub scratch_exists_with_type_cost_params: ScratchExistsWithTypeCostParams,
137
138 pub event_emit_cost_params: EventEmitCostParams,
140
141 pub borrow_uid_cost_params: BorrowUidCostParams,
143 pub delete_impl_cost_params: DeleteImplCostParams,
144 pub record_new_id_cost_params: RecordNewIdCostParams,
145
146 pub transfer_transfer_internal_cost_params: TransferInternalCostParams,
148 pub transfer_party_transfer_internal_cost_params: PartyTransferInternalCostParams,
149 pub transfer_freeze_object_cost_params: TransferFreezeObjectCostParams,
150 pub transfer_share_object_cost_params: TransferShareObjectCostParams,
151
152 pub tx_context_derive_id_cost_params: TxContextDeriveIdCostParams,
154 pub tx_context_fresh_id_cost_params: TxContextFreshIdCostParams,
155 pub tx_context_sender_cost_params: TxContextSenderCostParams,
156 pub tx_context_epoch_cost_params: TxContextEpochCostParams,
157 pub tx_context_epoch_timestamp_ms_cost_params: TxContextEpochTimestampMsCostParams,
158 pub tx_context_sponsor_cost_params: TxContextSponsorCostParams,
159 pub tx_context_rgp_cost_params: TxContextRGPCostParams,
160 pub tx_context_gas_price_cost_params: TxContextGasPriceCostParams,
161 pub tx_context_gas_budget_cost_params: TxContextGasBudgetCostParams,
162 pub tx_context_ids_created_cost_params: TxContextIdsCreatedCostParams,
163 pub tx_context_replace_cost_params: TxContextReplaceCostParams,
164
165 pub type_is_one_time_witness_cost_params: TypesIsOneTimeWitnessCostParams,
167
168 pub validator_validate_metadata_bcs_cost_params: ValidatorValidateMetadataBcsCostParams,
170
171 pub crypto_invalid_arguments_cost: InternalGas,
173 pub bls12381_bls12381_min_sig_verify_cost_params: Bls12381Bls12381MinSigVerifyCostParams,
175 pub bls12381_bls12381_min_pk_verify_cost_params: Bls12381Bls12381MinPkVerifyCostParams,
176
177 pub ecdsa_k1_ecrecover_cost_params: EcdsaK1EcrecoverCostParams,
179 pub ecdsa_k1_decompress_pubkey_cost_params: EcdsaK1DecompressPubkeyCostParams,
180 pub ecdsa_k1_secp256k1_verify_cost_params: EcdsaK1Secp256k1VerifyCostParams,
181
182 pub ecdsa_r1_ecrecover_cost_params: EcdsaR1EcrecoverCostParams,
184 pub ecdsa_r1_secp256_r1_verify_cost_params: EcdsaR1Secp256R1VerifyCostParams,
185
186 pub ecvrf_ecvrf_verify_cost_params: EcvrfEcvrfVerifyCostParams,
188
189 pub ed25519_verify_cost_params: Ed25519VerifyCostParams,
191
192 pub groth16_prepare_verifying_key_cost_params: Groth16PrepareVerifyingKeyCostParams,
194 pub groth16_verify_groth16_proof_internal_cost_params:
195 Groth16VerifyGroth16ProofInternalCostParams,
196
197 pub hash_blake2b256_cost_params: HashBlake2b256CostParams,
199 pub hash_keccak256_cost_params: HashKeccak256CostParams,
200
201 pub poseidon_bn254_cost_params: PoseidonBN254CostParams,
203
204 pub hmac_hmac_sha3_256_cost_params: HmacHmacSha3256CostParams,
206
207 pub group_ops_cost_params: GroupOpsCostParams,
209
210 pub vdf_cost_params: VDFCostParams,
212
213 pub check_zklogin_id_cost_params: CheckZkloginIdCostParams,
215 pub check_zklogin_issuer_cost_params: CheckZkloginIssuerCostParams,
216
217 pub transfer_receive_object_internal_cost_params: TransferReceiveObjectInternalCostParams,
219
220 pub nitro_attestation_cost_params: NitroAttestationCostParams,
222
223 pub bulletproofs_cost_params: BulletproofsCostParams,
225}
226
227impl NativeExtensionMarker<'_> for NativesCostTable {}
228
229impl NativesCostTable {
230 pub fn from_protocol_config(protocol_config: &ProtocolConfig) -> NativesCostTable {
231 Self {
232 address_from_bytes_cost_params: AddressFromBytesCostParams {
233 address_from_bytes_cost_base: protocol_config.address_from_bytes_cost_base().into(),
234 },
235 address_to_u256_cost_params: AddressToU256CostParams {
236 address_to_u256_cost_base: protocol_config.address_to_u256_cost_base().into(),
237 },
238 address_from_u256_cost_params: AddressFromU256CostParams {
239 address_from_u256_cost_base: protocol_config.address_from_u256_cost_base().into(),
240 },
241
242 config_read_setting_impl_cost_params: ConfigReadSettingImplCostParams {
243 config_read_setting_impl_cost_base: protocol_config
244 .config_read_setting_impl_cost_base_as_option()
245 .map(Into::into),
246 config_read_setting_impl_cost_per_byte: protocol_config
247 .config_read_setting_impl_cost_per_byte_as_option()
248 .map(Into::into),
249 },
250
251 package_original_package_id_impl_cost_params:
252 PackageVersioningOriginalPackageIdImplCostParams {
253 package_original_package_id_impl_cost_base: protocol_config
254 .package_original_package_id_impl_cost_base_as_option()
255 .map(Into::into),
256 package_original_package_id_impl_cost_per_byte: protocol_config
257 .package_original_package_id_impl_cost_per_byte_as_option()
258 .map(Into::into),
259 },
260
261 dynamic_field_hash_type_and_key_cost_params: DynamicFieldHashTypeAndKeyCostParams {
262 dynamic_field_hash_type_and_key_cost_base: protocol_config
263 .dynamic_field_hash_type_and_key_cost_base()
264 .into(),
265 dynamic_field_hash_type_and_key_type_cost_per_byte: protocol_config
266 .dynamic_field_hash_type_and_key_type_cost_per_byte()
267 .into(),
268 dynamic_field_hash_type_and_key_value_cost_per_byte: protocol_config
269 .dynamic_field_hash_type_and_key_value_cost_per_byte()
270 .into(),
271 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: protocol_config
272 .dynamic_field_hash_type_and_key_type_tag_cost_per_byte()
273 .into(),
274 },
275 dynamic_field_add_child_object_cost_params: DynamicFieldAddChildObjectCostParams {
276 dynamic_field_add_child_object_cost_base: protocol_config
277 .dynamic_field_add_child_object_cost_base()
278 .into(),
279 dynamic_field_add_child_object_type_cost_per_byte: protocol_config
280 .dynamic_field_add_child_object_type_cost_per_byte()
281 .into(),
282 dynamic_field_add_child_object_value_cost_per_byte: protocol_config
283 .dynamic_field_add_child_object_value_cost_per_byte()
284 .into(),
285 dynamic_field_add_child_object_struct_tag_cost_per_byte: protocol_config
286 .dynamic_field_add_child_object_struct_tag_cost_per_byte()
287 .into(),
288 },
289 dynamic_field_borrow_child_object_cost_params:
290 DynamicFieldBorrowChildObjectCostParams {
291 dynamic_field_borrow_child_object_cost_base: protocol_config
292 .dynamic_field_borrow_child_object_cost_base()
293 .into(),
294 dynamic_field_borrow_child_object_child_ref_cost_per_byte: protocol_config
295 .dynamic_field_borrow_child_object_child_ref_cost_per_byte()
296 .into(),
297 dynamic_field_borrow_child_object_type_cost_per_byte: protocol_config
298 .dynamic_field_borrow_child_object_type_cost_per_byte()
299 .into(),
300 },
301 dynamic_field_remove_child_object_cost_params:
302 DynamicFieldRemoveChildObjectCostParams {
303 dynamic_field_remove_child_object_cost_base: protocol_config
304 .dynamic_field_remove_child_object_cost_base()
305 .into(),
306 dynamic_field_remove_child_object_child_cost_per_byte: protocol_config
307 .dynamic_field_remove_child_object_child_cost_per_byte()
308 .into(),
309 dynamic_field_remove_child_object_type_cost_per_byte: protocol_config
310 .dynamic_field_remove_child_object_type_cost_per_byte()
311 .into(),
312 },
313 dynamic_field_has_child_object_cost_params: DynamicFieldHasChildObjectCostParams {
314 dynamic_field_has_child_object_cost_base: protocol_config
315 .dynamic_field_has_child_object_cost_base()
316 .into(),
317 },
318 dynamic_field_has_child_object_with_ty_cost_params:
319 DynamicFieldHasChildObjectWithTyCostParams {
320 dynamic_field_has_child_object_with_ty_cost_base: protocol_config
321 .dynamic_field_has_child_object_with_ty_cost_base()
322 .into(),
323 dynamic_field_has_child_object_with_ty_type_cost_per_byte: protocol_config
324 .dynamic_field_has_child_object_with_ty_type_cost_per_byte()
325 .into(),
326 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: protocol_config
327 .dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte()
328 .into(),
329 },
330
331 scratch_add_cost_params: ScratchAddCostParams {
332 scratch_add_cost_base: protocol_config
333 .scratch_add_cost_base_as_option()
334 .map(Into::into),
335 },
336 scratch_read_cost_params: ScratchReadCostParams {
337 scratch_read_cost_base: protocol_config
338 .scratch_read_cost_base_as_option()
339 .map(Into::into),
340 scratch_read_value_cost: protocol_config
341 .scratch_read_value_cost_as_option()
342 .map(Into::into),
343 },
344 scratch_remove_cost_params: ScratchRemoveCostParams {
345 scratch_remove_cost_base: protocol_config
346 .scratch_remove_cost_base_as_option()
347 .map(Into::into),
348 },
349 scratch_exists_cost_params: ScratchExistsCostParams {
350 scratch_exists_cost_base: protocol_config
351 .scratch_exists_cost_base_as_option()
352 .map(Into::into),
353 },
354 scratch_exists_with_type_cost_params: ScratchExistsWithTypeCostParams {
355 scratch_exists_with_type_cost_base: protocol_config
356 .scratch_exists_with_type_cost_base_as_option()
357 .map(Into::into),
358 scratch_exists_with_type_type_cost: protocol_config
359 .scratch_exists_with_type_type_cost_as_option()
360 .map(Into::into),
361 },
362
363 event_emit_cost_params: EventEmitCostParams {
364 event_emit_value_size_derivation_cost_per_byte: protocol_config
365 .event_emit_value_size_derivation_cost_per_byte()
366 .into(),
367 event_emit_tag_size_derivation_cost_per_byte: protocol_config
368 .event_emit_tag_size_derivation_cost_per_byte()
369 .into(),
370 event_emit_output_cost_per_byte: protocol_config
371 .event_emit_output_cost_per_byte()
372 .into(),
373 event_emit_cost_base: protocol_config.event_emit_cost_base().into(),
374 event_emit_auth_stream_cost: protocol_config
375 .event_emit_auth_stream_cost_as_option()
376 .map(Into::into),
377 },
378
379 borrow_uid_cost_params: BorrowUidCostParams {
380 object_borrow_uid_cost_base: protocol_config.object_borrow_uid_cost_base().into(),
381 },
382 delete_impl_cost_params: DeleteImplCostParams {
383 object_delete_impl_cost_base: protocol_config.object_delete_impl_cost_base().into(),
384 },
385 record_new_id_cost_params: RecordNewIdCostParams {
386 object_record_new_uid_cost_base: protocol_config
387 .object_record_new_uid_cost_base()
388 .into(),
389 object_record_new_uid_from_hash_cost_base: protocol_config
390 .object_record_new_uid_from_hash_cost_base_as_option()
391 .map(Into::into),
392 },
393
394 crypto_invalid_arguments_cost: protocol_config.crypto_invalid_arguments_cost().into(),
396 ed25519_verify_cost_params: Ed25519VerifyCostParams {
398 ed25519_ed25519_verify_cost_base: protocol_config
399 .ed25519_ed25519_verify_cost_base()
400 .into(),
401 ed25519_ed25519_verify_msg_cost_per_byte: protocol_config
402 .ed25519_ed25519_verify_msg_cost_per_byte()
403 .into(),
404 ed25519_ed25519_verify_msg_cost_per_block: protocol_config
405 .ed25519_ed25519_verify_msg_cost_per_block()
406 .into(),
407 },
408 hash_blake2b256_cost_params: HashBlake2b256CostParams {
410 hash_blake2b256_cost_base: protocol_config.hash_blake2b256_cost_base().into(),
411 hash_blake2b256_data_cost_per_byte: protocol_config
412 .hash_blake2b256_data_cost_per_byte()
413 .into(),
414 hash_blake2b256_data_cost_per_block: protocol_config
415 .hash_blake2b256_data_cost_per_block()
416 .into(),
417 },
418 hash_keccak256_cost_params: HashKeccak256CostParams {
419 hash_keccak256_cost_base: protocol_config.hash_keccak256_cost_base().into(),
420 hash_keccak256_data_cost_per_byte: protocol_config
421 .hash_keccak256_data_cost_per_byte()
422 .into(),
423 hash_keccak256_data_cost_per_block: protocol_config
424 .hash_keccak256_data_cost_per_block()
425 .into(),
426 },
427 transfer_transfer_internal_cost_params: TransferInternalCostParams {
428 transfer_transfer_internal_cost_base: protocol_config
429 .transfer_transfer_internal_cost_base()
430 .into(),
431 },
432 transfer_party_transfer_internal_cost_params: PartyTransferInternalCostParams {
433 transfer_party_transfer_internal_cost_base: protocol_config
434 .transfer_party_transfer_internal_cost_base_as_option()
435 .map(Into::into),
436 },
437 transfer_freeze_object_cost_params: TransferFreezeObjectCostParams {
438 transfer_freeze_object_cost_base: protocol_config
439 .transfer_freeze_object_cost_base()
440 .into(),
441 },
442 transfer_share_object_cost_params: TransferShareObjectCostParams {
443 transfer_share_object_cost_base: protocol_config
444 .transfer_share_object_cost_base()
445 .into(),
446 },
447 tx_context_derive_id_cost_params: TxContextDeriveIdCostParams {
449 tx_context_derive_id_cost_base: protocol_config
450 .tx_context_derive_id_cost_base()
451 .into(),
452 },
453 tx_context_fresh_id_cost_params: TxContextFreshIdCostParams {
454 tx_context_fresh_id_cost_base: protocol_config
455 .tx_context_fresh_id_cost_base()
456 .into(),
457 },
458 tx_context_sender_cost_params: TxContextSenderCostParams {
459 tx_context_sender_cost_base: protocol_config.tx_context_sender_cost_base().into(),
460 },
461 tx_context_epoch_cost_params: TxContextEpochCostParams {
462 tx_context_epoch_cost_base: protocol_config.tx_context_epoch_cost_base().into(),
463 },
464 tx_context_epoch_timestamp_ms_cost_params: TxContextEpochTimestampMsCostParams {
465 tx_context_epoch_timestamp_ms_cost_base: protocol_config
466 .tx_context_epoch_timestamp_ms_cost_base()
467 .into(),
468 },
469 tx_context_sponsor_cost_params: TxContextSponsorCostParams {
470 tx_context_sponsor_cost_base: protocol_config.tx_context_sponsor_cost_base().into(),
471 },
472 tx_context_rgp_cost_params: TxContextRGPCostParams {
473 tx_context_rgp_cost_base: protocol_config
474 .tx_context_rgp_cost_base_as_option()
475 .unwrap_or(DEFAULT_UNUSED_TX_CONTEXT_ENTRY_COST)
476 .into(),
477 },
478 tx_context_gas_price_cost_params: TxContextGasPriceCostParams {
479 tx_context_gas_price_cost_base: protocol_config
480 .tx_context_gas_price_cost_base()
481 .into(),
482 },
483 tx_context_gas_budget_cost_params: TxContextGasBudgetCostParams {
484 tx_context_gas_budget_cost_base: protocol_config
485 .tx_context_gas_budget_cost_base()
486 .into(),
487 },
488 tx_context_ids_created_cost_params: TxContextIdsCreatedCostParams {
489 tx_context_ids_created_cost_base: protocol_config
490 .tx_context_ids_created_cost_base()
491 .into(),
492 },
493 tx_context_replace_cost_params: TxContextReplaceCostParams {
494 tx_context_replace_cost_base: protocol_config.tx_context_replace_cost_base().into(),
495 },
496 type_is_one_time_witness_cost_params: TypesIsOneTimeWitnessCostParams {
497 types_is_one_time_witness_cost_base: protocol_config
498 .types_is_one_time_witness_cost_base()
499 .into(),
500 types_is_one_time_witness_type_tag_cost_per_byte: protocol_config
501 .types_is_one_time_witness_type_tag_cost_per_byte()
502 .into(),
503 types_is_one_time_witness_type_cost_per_byte: protocol_config
504 .types_is_one_time_witness_type_cost_per_byte()
505 .into(),
506 },
507 validator_validate_metadata_bcs_cost_params: ValidatorValidateMetadataBcsCostParams {
508 validator_validate_metadata_cost_base: protocol_config
509 .validator_validate_metadata_cost_base()
510 .into(),
511 validator_validate_metadata_data_cost_per_byte: protocol_config
512 .validator_validate_metadata_data_cost_per_byte()
513 .into(),
514 },
515 bls12381_bls12381_min_sig_verify_cost_params: Bls12381Bls12381MinSigVerifyCostParams {
516 bls12381_bls12381_min_sig_verify_cost_base: protocol_config
517 .bls12381_bls12381_min_sig_verify_cost_base()
518 .into(),
519 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: protocol_config
520 .bls12381_bls12381_min_sig_verify_msg_cost_per_byte()
521 .into(),
522 bls12381_bls12381_min_sig_verify_msg_cost_per_block: protocol_config
523 .bls12381_bls12381_min_sig_verify_msg_cost_per_block()
524 .into(),
525 },
526 bls12381_bls12381_min_pk_verify_cost_params: Bls12381Bls12381MinPkVerifyCostParams {
527 bls12381_bls12381_min_pk_verify_cost_base: protocol_config
528 .bls12381_bls12381_min_pk_verify_cost_base()
529 .into(),
530 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: protocol_config
531 .bls12381_bls12381_min_pk_verify_msg_cost_per_byte()
532 .into(),
533 bls12381_bls12381_min_pk_verify_msg_cost_per_block: protocol_config
534 .bls12381_bls12381_min_pk_verify_msg_cost_per_block()
535 .into(),
536 },
537 ecdsa_k1_ecrecover_cost_params: EcdsaK1EcrecoverCostParams {
538 ecdsa_k1_ecrecover_keccak256_cost_base: protocol_config
539 .ecdsa_k1_ecrecover_keccak256_cost_base()
540 .into(),
541 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: protocol_config
542 .ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte()
543 .into(),
544 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: protocol_config
545 .ecdsa_k1_ecrecover_keccak256_msg_cost_per_block()
546 .into(),
547 ecdsa_k1_ecrecover_sha256_cost_base: protocol_config
548 .ecdsa_k1_ecrecover_sha256_cost_base()
549 .into(),
550 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: protocol_config
551 .ecdsa_k1_ecrecover_sha256_msg_cost_per_byte()
552 .into(),
553 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: protocol_config
554 .ecdsa_k1_ecrecover_sha256_msg_cost_per_block()
555 .into(),
556 },
557 ecdsa_k1_decompress_pubkey_cost_params: EcdsaK1DecompressPubkeyCostParams {
558 ecdsa_k1_decompress_pubkey_cost_base: protocol_config
559 .ecdsa_k1_decompress_pubkey_cost_base()
560 .into(),
561 },
562 ecdsa_k1_secp256k1_verify_cost_params: EcdsaK1Secp256k1VerifyCostParams {
563 ecdsa_k1_secp256k1_verify_keccak256_cost_base: protocol_config
564 .ecdsa_k1_secp256k1_verify_keccak256_cost_base()
565 .into(),
566 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: protocol_config
567 .ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte()
568 .into(),
569 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: protocol_config
570 .ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block()
571 .into(),
572 ecdsa_k1_secp256k1_verify_sha256_cost_base: protocol_config
573 .ecdsa_k1_secp256k1_verify_sha256_cost_base()
574 .into(),
575 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: protocol_config
576 .ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte()
577 .into(),
578 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: protocol_config
579 .ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block()
580 .into(),
581 },
582 ecdsa_r1_ecrecover_cost_params: EcdsaR1EcrecoverCostParams {
583 ecdsa_r1_ecrecover_keccak256_cost_base: protocol_config
584 .ecdsa_r1_ecrecover_keccak256_cost_base()
585 .into(),
586 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: protocol_config
587 .ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte()
588 .into(),
589 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: protocol_config
590 .ecdsa_r1_ecrecover_keccak256_msg_cost_per_block()
591 .into(),
592 ecdsa_r1_ecrecover_sha256_cost_base: protocol_config
593 .ecdsa_r1_ecrecover_sha256_cost_base()
594 .into(),
595 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: protocol_config
596 .ecdsa_r1_ecrecover_sha256_msg_cost_per_byte()
597 .into(),
598 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: protocol_config
599 .ecdsa_r1_ecrecover_sha256_msg_cost_per_block()
600 .into(),
601 },
602 ecdsa_r1_secp256_r1_verify_cost_params: EcdsaR1Secp256R1VerifyCostParams {
603 ecdsa_r1_secp256r1_verify_keccak256_cost_base: protocol_config
604 .ecdsa_r1_secp256r1_verify_keccak256_cost_base()
605 .into(),
606 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: protocol_config
607 .ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte()
608 .into(),
609 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: protocol_config
610 .ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block()
611 .into(),
612 ecdsa_r1_secp256r1_verify_sha256_cost_base: protocol_config
613 .ecdsa_r1_secp256r1_verify_sha256_cost_base()
614 .into(),
615 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: protocol_config
616 .ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte()
617 .into(),
618 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: protocol_config
619 .ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block()
620 .into(),
621 },
622 ecvrf_ecvrf_verify_cost_params: EcvrfEcvrfVerifyCostParams {
623 ecvrf_ecvrf_verify_cost_base: protocol_config.ecvrf_ecvrf_verify_cost_base().into(),
624 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: protocol_config
625 .ecvrf_ecvrf_verify_alpha_string_cost_per_byte()
626 .into(),
627 ecvrf_ecvrf_verify_alpha_string_cost_per_block: protocol_config
628 .ecvrf_ecvrf_verify_alpha_string_cost_per_block()
629 .into(),
630 },
631 groth16_prepare_verifying_key_cost_params: Groth16PrepareVerifyingKeyCostParams {
632 groth16_prepare_verifying_key_bls12381_cost_base: protocol_config
633 .groth16_prepare_verifying_key_bls12381_cost_base()
634 .into(),
635 groth16_prepare_verifying_key_bn254_cost_base: protocol_config
636 .groth16_prepare_verifying_key_bn254_cost_base()
637 .into(),
638 },
639 groth16_verify_groth16_proof_internal_cost_params:
640 Groth16VerifyGroth16ProofInternalCostParams {
641 groth16_verify_groth16_proof_internal_bls12381_cost_base: protocol_config
642 .groth16_verify_groth16_proof_internal_bls12381_cost_base()
643 .into(),
644 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input:
645 protocol_config
646 .groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input()
647 .into(),
648 groth16_verify_groth16_proof_internal_bn254_cost_base: protocol_config
649 .groth16_verify_groth16_proof_internal_bn254_cost_base()
650 .into(),
651 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input:
652 protocol_config
653 .groth16_verify_groth16_proof_internal_bn254_cost_per_public_input()
654 .into(),
655 groth16_verify_groth16_proof_internal_public_input_cost_per_byte:
656 protocol_config
657 .groth16_verify_groth16_proof_internal_public_input_cost_per_byte()
658 .into(),
659 },
660 hmac_hmac_sha3_256_cost_params: HmacHmacSha3256CostParams {
661 hmac_hmac_sha3_256_cost_base: protocol_config.hmac_hmac_sha3_256_cost_base().into(),
662 hmac_hmac_sha3_256_input_cost_per_byte: protocol_config
663 .hmac_hmac_sha3_256_input_cost_per_byte()
664 .into(),
665 hmac_hmac_sha3_256_input_cost_per_block: protocol_config
666 .hmac_hmac_sha3_256_input_cost_per_block()
667 .into(),
668 },
669 transfer_receive_object_internal_cost_params: TransferReceiveObjectInternalCostParams {
670 transfer_receive_object_internal_cost_base: protocol_config
671 .transfer_receive_object_cost_base_as_option()
672 .unwrap_or(0)
673 .into(),
674 transfer_receive_object_internal_cost_per_byte: protocol_config
675 .transfer_receive_object_cost_per_byte_as_option()
676 .unwrap_or(0)
677 .into(),
678 transfer_receive_object_internal_type_cost_per_byte: protocol_config
679 .transfer_receive_object_type_cost_per_byte_as_option()
680 .unwrap_or(0)
681 .into(),
682 },
683 check_zklogin_id_cost_params: CheckZkloginIdCostParams {
684 check_zklogin_id_cost_base: protocol_config
685 .check_zklogin_id_cost_base_as_option()
686 .map(Into::into),
687 },
688 check_zklogin_issuer_cost_params: CheckZkloginIssuerCostParams {
689 check_zklogin_issuer_cost_base: protocol_config
690 .check_zklogin_issuer_cost_base_as_option()
691 .map(Into::into),
692 },
693 poseidon_bn254_cost_params: PoseidonBN254CostParams {
694 poseidon_bn254_cost_base: protocol_config
695 .poseidon_bn254_cost_base_as_option()
696 .map(Into::into),
697 poseidon_bn254_data_cost_per_block: protocol_config
698 .poseidon_bn254_cost_per_block_as_option()
699 .map(Into::into),
700 },
701 group_ops_cost_params: GroupOpsCostParams {
702 bls12381_decode_scalar_cost: protocol_config
703 .group_ops_bls12381_decode_scalar_cost_as_option()
704 .map(Into::into),
705 bls12381_decode_g1_cost: protocol_config
706 .group_ops_bls12381_decode_g1_cost_as_option()
707 .map(Into::into),
708 bls12381_decode_g2_cost: protocol_config
709 .group_ops_bls12381_decode_g2_cost_as_option()
710 .map(Into::into),
711 bls12381_decode_gt_cost: protocol_config
712 .group_ops_bls12381_decode_gt_cost_as_option()
713 .map(Into::into),
714 bls12381_scalar_add_cost: protocol_config
715 .group_ops_bls12381_scalar_add_cost_as_option()
716 .map(Into::into),
717 bls12381_g1_add_cost: protocol_config
718 .group_ops_bls12381_g1_add_cost_as_option()
719 .map(Into::into),
720 bls12381_g2_add_cost: protocol_config
721 .group_ops_bls12381_g2_add_cost_as_option()
722 .map(Into::into),
723 bls12381_gt_add_cost: protocol_config
724 .group_ops_bls12381_gt_add_cost_as_option()
725 .map(Into::into),
726 bls12381_scalar_sub_cost: protocol_config
727 .group_ops_bls12381_scalar_sub_cost_as_option()
728 .map(Into::into),
729 bls12381_g1_sub_cost: protocol_config
730 .group_ops_bls12381_g1_sub_cost_as_option()
731 .map(Into::into),
732 bls12381_g2_sub_cost: protocol_config
733 .group_ops_bls12381_g2_sub_cost_as_option()
734 .map(Into::into),
735 bls12381_gt_sub_cost: protocol_config
736 .group_ops_bls12381_gt_sub_cost_as_option()
737 .map(Into::into),
738 bls12381_scalar_mul_cost: protocol_config
739 .group_ops_bls12381_scalar_mul_cost_as_option()
740 .map(Into::into),
741 bls12381_g1_mul_cost: protocol_config
742 .group_ops_bls12381_g1_mul_cost_as_option()
743 .map(Into::into),
744 bls12381_g2_mul_cost: protocol_config
745 .group_ops_bls12381_g2_mul_cost_as_option()
746 .map(Into::into),
747 bls12381_gt_mul_cost: protocol_config
748 .group_ops_bls12381_gt_mul_cost_as_option()
749 .map(Into::into),
750 bls12381_scalar_div_cost: protocol_config
751 .group_ops_bls12381_scalar_div_cost_as_option()
752 .map(Into::into),
753 bls12381_g1_div_cost: protocol_config
754 .group_ops_bls12381_g1_div_cost_as_option()
755 .map(Into::into),
756 bls12381_g2_div_cost: protocol_config
757 .group_ops_bls12381_g2_div_cost_as_option()
758 .map(Into::into),
759 bls12381_gt_div_cost: protocol_config
760 .group_ops_bls12381_gt_div_cost_as_option()
761 .map(Into::into),
762 bls12381_g1_hash_to_base_cost: protocol_config
763 .group_ops_bls12381_g1_hash_to_base_cost_as_option()
764 .map(Into::into),
765 bls12381_g2_hash_to_base_cost: protocol_config
766 .group_ops_bls12381_g2_hash_to_base_cost_as_option()
767 .map(Into::into),
768 bls12381_g1_hash_to_cost_per_byte: protocol_config
769 .group_ops_bls12381_g1_hash_to_cost_per_byte_as_option()
770 .map(Into::into),
771 bls12381_g2_hash_to_cost_per_byte: protocol_config
772 .group_ops_bls12381_g2_hash_to_cost_per_byte_as_option()
773 .map(Into::into),
774 bls12381_g1_msm_base_cost: protocol_config
775 .group_ops_bls12381_g1_msm_base_cost_as_option()
776 .map(Into::into),
777 bls12381_g2_msm_base_cost: protocol_config
778 .group_ops_bls12381_g2_msm_base_cost_as_option()
779 .map(Into::into),
780 bls12381_g1_msm_base_cost_per_input: protocol_config
781 .group_ops_bls12381_g1_msm_base_cost_per_input_as_option()
782 .map(Into::into),
783 bls12381_g2_msm_base_cost_per_input: protocol_config
784 .group_ops_bls12381_g2_msm_base_cost_per_input_as_option()
785 .map(Into::into),
786 bls12381_msm_max_len: protocol_config.group_ops_bls12381_msm_max_len_as_option(),
787 bls12381_pairing_cost: protocol_config
788 .group_ops_bls12381_pairing_cost_as_option()
789 .map(Into::into),
790 bls12381_g1_to_uncompressed_g1_cost: protocol_config
791 .group_ops_bls12381_g1_to_uncompressed_g1_cost_as_option()
792 .map(Into::into),
793 bls12381_uncompressed_g1_to_g1_cost: protocol_config
794 .group_ops_bls12381_uncompressed_g1_to_g1_cost_as_option()
795 .map(Into::into),
796 bls12381_uncompressed_g1_sum_base_cost: protocol_config
797 .group_ops_bls12381_uncompressed_g1_sum_base_cost_as_option()
798 .map(Into::into),
799 bls12381_uncompressed_g1_sum_cost_per_term: protocol_config
800 .group_ops_bls12381_uncompressed_g1_sum_cost_per_term_as_option()
801 .map(Into::into),
802 bls12381_uncompressed_g1_sum_max_terms: protocol_config
803 .group_ops_bls12381_uncompressed_g1_sum_max_terms_as_option(),
804 ristretto_decode_scalar_cost: protocol_config
805 .group_ops_ristretto_decode_scalar_cost_as_option()
806 .map(Into::into),
807 ristretto_decode_point_cost: protocol_config
808 .group_ops_ristretto_decode_point_cost_as_option()
809 .map(Into::into),
810 ristretto_scalar_add_cost: protocol_config
811 .group_ops_ristretto_scalar_add_cost_as_option()
812 .map(Into::into),
813 ristretto_point_add_cost: protocol_config
814 .group_ops_ristretto_point_add_cost_as_option()
815 .map(Into::into),
816 ristretto_scalar_sub_cost: protocol_config
817 .group_ops_ristretto_scalar_sub_cost_as_option()
818 .map(Into::into),
819 ristretto_point_sub_cost: protocol_config
820 .group_ops_ristretto_point_sub_cost_as_option()
821 .map(Into::into),
822 ristretto_scalar_mul_cost: protocol_config
823 .group_ops_ristretto_scalar_mul_cost_as_option()
824 .map(Into::into),
825 ristretto_point_mul_cost: protocol_config
826 .group_ops_ristretto_point_mul_cost_as_option()
827 .map(Into::into),
828 ristretto_scalar_div_cost: protocol_config
829 .group_ops_ristretto_scalar_div_cost_as_option()
830 .map(Into::into),
831 ristretto_point_div_cost: protocol_config
832 .group_ops_ristretto_point_div_cost_as_option()
833 .map(Into::into),
834 },
835 vdf_cost_params: VDFCostParams {
836 vdf_verify_cost: protocol_config
837 .vdf_verify_vdf_cost_as_option()
838 .map(Into::into),
839 hash_to_input_cost: protocol_config
840 .vdf_hash_to_input_cost_as_option()
841 .map(Into::into),
842 },
843 nitro_attestation_cost_params: NitroAttestationCostParams {
844 parse_base_cost: protocol_config
845 .nitro_attestation_parse_base_cost_as_option()
846 .map(Into::into),
847 parse_cost_per_byte: protocol_config
848 .nitro_attestation_parse_cost_per_byte_as_option()
849 .map(Into::into),
850 verify_base_cost: protocol_config
851 .nitro_attestation_verify_base_cost_as_option()
852 .map(Into::into),
853 verify_cost_per_cert: protocol_config
854 .nitro_attestation_verify_cost_per_cert_as_option()
855 .map(Into::into),
856 },
857 bulletproofs_cost_params: BulletproofsCostParams {
858 verify_bulletproofs_ristretto255_base_cost: protocol_config
859 .verify_bulletproofs_ristretto255_base_cost_as_option()
860 .map(Into::into),
861 verify_bulletproofs_ristretto255_cost_per_bit_and_commitment: protocol_config
862 .verify_bulletproofs_ristretto255_cost_per_bit_and_commitment_as_option()
863 .map(Into::into),
864 },
865 }
866 }
867}
868
869pub fn make_stdlib_gas_params_for_protocol_config(
870 protocol_config: &ProtocolConfig,
871) -> GasParameters {
872 macro_rules! get_gas_cost_or_default {
873 ($name: ident) => {{
874 debug_assert!(
875 protocol_config.version.as_u64() < 53 || protocol_config.$name().is_some()
876 );
877 protocol_config.$name().map(Into::into).unwrap_or(0.into())
878 }};
879 }
880 GasParameters::new(
881 MSN::bcs::GasParameters {
882 to_bytes: MSN::bcs::ToBytesGasParameters {
883 per_byte_serialized: get_gas_cost_or_default!(
884 bcs_per_byte_serialized_cost_as_option
885 ),
886 legacy_min_output_size: get_gas_cost_or_default!(
887 bcs_legacy_min_output_size_cost_as_option
888 ),
889 failure: get_gas_cost_or_default!(bcs_failure_cost_as_option),
890 },
891 },
892 MSN::debug::GasParameters {
893 print: MSN::debug::PrintGasParameters {
894 base_cost: get_gas_cost_or_default!(debug_print_base_cost_as_option),
895 },
896 print_stack_trace: MSN::debug::PrintStackTraceGasParameters {
897 base_cost: get_gas_cost_or_default!(debug_print_stack_trace_base_cost_as_option),
898 },
899 },
900 MSN::hash::GasParameters {
901 sha2_256: MSN::hash::Sha2_256GasParameters {
902 base: get_gas_cost_or_default!(hash_sha2_256_base_cost_as_option),
903 per_byte: get_gas_cost_or_default!(hash_sha2_256_per_byte_cost_as_option),
904 legacy_min_input_len: get_gas_cost_or_default!(
905 hash_sha2_256_legacy_min_input_len_cost_as_option
906 ),
907 },
908 sha3_256: MSN::hash::Sha3_256GasParameters {
909 base: get_gas_cost_or_default!(hash_sha3_256_base_cost_as_option),
910 per_byte: get_gas_cost_or_default!(hash_sha3_256_per_byte_cost_as_option),
911 legacy_min_input_len: get_gas_cost_or_default!(
912 hash_sha3_256_legacy_min_input_len_cost_as_option
913 ),
914 },
915 },
916 MSN::string::GasParameters {
917 check_utf8: MSN::string::CheckUtf8GasParameters {
918 base: get_gas_cost_or_default!(string_check_utf8_base_cost_as_option),
919 per_byte: get_gas_cost_or_default!(string_check_utf8_per_byte_cost_as_option),
920 },
921 is_char_boundary: MSN::string::IsCharBoundaryGasParameters {
922 base: get_gas_cost_or_default!(string_is_char_boundary_base_cost_as_option),
923 },
924 sub_string: MSN::string::SubStringGasParameters {
925 base: get_gas_cost_or_default!(string_sub_string_base_cost_as_option),
926 per_byte: get_gas_cost_or_default!(string_sub_string_per_byte_cost_as_option),
927 },
928 index_of: MSN::string::IndexOfGasParameters {
929 base: get_gas_cost_or_default!(string_index_of_base_cost_as_option),
930 per_byte_pattern: get_gas_cost_or_default!(
931 string_index_of_per_byte_pattern_cost_as_option
932 ),
933 per_byte_searched: get_gas_cost_or_default!(
934 string_index_of_per_byte_searched_cost_as_option
935 ),
936 },
937 },
938 MSN::type_name::GasParameters {
939 get: MSN::type_name::GetGasParameters {
940 base: get_gas_cost_or_default!(type_name_get_base_cost_as_option),
941 per_byte: get_gas_cost_or_default!(type_name_get_per_byte_cost_as_option),
942 },
943 id: MSN::type_name::IdGasParameters::new(
944 protocol_config.type_name_id_base_cost_as_option(),
945 ),
946 },
947 MSN::vector::GasParameters {
948 empty: MSN::vector::EmptyGasParameters {
949 base: get_gas_cost_or_default!(vector_empty_base_cost_as_option),
950 },
951 length: MSN::vector::LengthGasParameters {
952 base: get_gas_cost_or_default!(vector_length_base_cost_as_option),
953 },
954 push_back: MSN::vector::PushBackGasParameters {
955 base: get_gas_cost_or_default!(vector_push_back_base_cost_as_option),
956 legacy_per_abstract_memory_unit: get_gas_cost_or_default!(
957 vector_push_back_legacy_per_abstract_memory_unit_cost_as_option
958 ),
959 },
960 borrow: MSN::vector::BorrowGasParameters {
961 base: get_gas_cost_or_default!(vector_borrow_base_cost_as_option),
962 },
963 pop_back: MSN::vector::PopBackGasParameters {
964 base: get_gas_cost_or_default!(vector_pop_back_base_cost_as_option),
965 },
966 destroy_empty: MSN::vector::DestroyEmptyGasParameters {
967 base: get_gas_cost_or_default!(vector_destroy_empty_base_cost_as_option),
968 },
969 swap: MSN::vector::SwapGasParameters {
970 base: get_gas_cost_or_default!(vector_swap_base_cost_as_option),
971 },
972 },
973 )
974}
975
976pub fn all_natives(silent: bool, protocol_config: &ProtocolConfig) -> NativeFunctionTable {
977 let sui_framework_natives: &[(&str, &str, NativeFunction)] = &[
978 (
979 "accumulator",
980 "emit_deposit_event",
981 make_native!(accumulator::emit_deposit_event),
982 ),
983 (
984 "accumulator",
985 "emit_withdraw_event",
986 make_native!(accumulator::emit_withdraw_event),
987 ),
988 (
989 "accumulator_settlement",
990 "record_settlement_sui_conservation",
991 make_native!(accumulator::record_settlement_sui_conservation),
992 ),
993 ("address", "from_bytes", make_native!(address::from_bytes)),
994 ("address", "to_u256", make_native!(address::to_u256)),
995 ("address", "from_u256", make_native!(address::from_u256)),
996 ("hash", "blake2b256", make_native!(hash::blake2b256)),
997 (
998 "bls12381",
999 "bls12381_min_sig_verify",
1000 make_native!(bls12381::bls12381_min_sig_verify),
1001 ),
1002 (
1003 "bls12381",
1004 "bls12381_min_pk_verify",
1005 make_native!(bls12381::bls12381_min_pk_verify),
1006 ),
1007 (
1008 "dynamic_field",
1009 "hash_type_and_key",
1010 make_native!(dynamic_field::hash_type_and_key),
1011 ),
1012 (
1013 "config",
1014 "read_setting_impl",
1015 make_native!(config::read_setting_impl),
1016 ),
1017 (
1018 "package",
1019 "original_package_id_impl",
1020 make_native!(package::original_package_id_impl),
1021 ),
1022 (
1023 "dynamic_field",
1024 "add_child_object",
1025 make_native!(dynamic_field::add_child_object),
1026 ),
1027 (
1028 "dynamic_field",
1029 "borrow_child_object",
1030 make_native!(dynamic_field::borrow_child_object),
1031 ),
1032 (
1033 "dynamic_field",
1034 "borrow_child_object_mut",
1035 make_native!(dynamic_field::borrow_child_object),
1036 ),
1037 (
1038 "dynamic_field",
1039 "remove_child_object",
1040 make_native!(dynamic_field::remove_child_object),
1041 ),
1042 (
1043 "dynamic_field",
1044 "has_child_object",
1045 make_native!(dynamic_field::has_child_object),
1046 ),
1047 (
1048 "dynamic_field",
1049 "has_child_object_with_ty",
1050 make_native!(dynamic_field::has_child_object_with_ty),
1051 ),
1052 ("scratch", "add_impl", make_native!(scratch::add_impl)),
1053 ("scratch", "read_impl", make_native!(scratch::read_impl)),
1054 ("scratch", "remove_impl", make_native!(scratch::remove_impl)),
1055 ("scratch", "exists_impl", make_native!(scratch::exists_impl)),
1056 (
1057 "scratch",
1058 "exists_with_type_impl",
1059 make_native!(scratch::exists_with_type_impl),
1060 ),
1061 (
1062 "ecdsa_k1",
1063 "secp256k1_ecrecover",
1064 make_native!(ecdsa_k1::ecrecover),
1065 ),
1066 (
1067 "ecdsa_k1",
1068 "decompress_pubkey",
1069 make_native!(ecdsa_k1::decompress_pubkey),
1070 ),
1071 (
1072 "ecdsa_k1",
1073 "secp256k1_verify",
1074 make_native!(ecdsa_k1::secp256k1_verify),
1075 ),
1076 ("ecvrf", "ecvrf_verify", make_native!(ecvrf::ecvrf_verify)),
1077 (
1078 "ecdsa_r1",
1079 "secp256r1_ecrecover",
1080 make_native!(ecdsa_r1::ecrecover),
1081 ),
1082 (
1083 "ecdsa_r1",
1084 "secp256r1_verify",
1085 make_native!(ecdsa_r1::secp256r1_verify),
1086 ),
1087 (
1088 "ed25519",
1089 "ed25519_verify",
1090 make_native!(ed25519::ed25519_verify),
1091 ),
1092 ("event", "emit", make_native!(event::emit)),
1093 (
1094 "event",
1095 "emit_authenticated_impl",
1096 make_native!(event::emit_authenticated_impl),
1097 ),
1098 (
1099 "event",
1100 "events_by_type",
1101 make_native!(event::get_events_by_type),
1102 ),
1103 ("event", "num_events", make_native!(event::num_events)),
1104 (
1105 "funds_accumulator",
1106 "add_to_accumulator_address",
1107 make_native!(funds_accumulator::add_to_accumulator_address),
1108 ),
1109 (
1110 "funds_accumulator",
1111 "withdraw_from_accumulator_address",
1112 make_native!(funds_accumulator::withdraw_from_accumulator_address),
1113 ),
1114 (
1115 "groth16",
1116 "verify_groth16_proof_internal",
1117 make_native!(groth16::verify_groth16_proof_internal),
1118 ),
1119 (
1120 "groth16",
1121 "prepare_verifying_key_internal",
1122 make_native!(groth16::prepare_verifying_key_internal),
1123 ),
1124 ("hmac", "hmac_sha3_256", make_native!(hmac::hmac_sha3_256)),
1125 ("hash", "keccak256", make_native!(hash::keccak256)),
1126 (
1127 "group_ops",
1128 "internal_validate",
1129 make_native!(group_ops::internal_validate),
1130 ),
1131 (
1132 "group_ops",
1133 "internal_add",
1134 make_native!(group_ops::internal_add),
1135 ),
1136 (
1137 "group_ops",
1138 "internal_sub",
1139 make_native!(group_ops::internal_sub),
1140 ),
1141 (
1142 "group_ops",
1143 "internal_mul",
1144 make_native!(group_ops::internal_mul),
1145 ),
1146 (
1147 "group_ops",
1148 "internal_div",
1149 make_native!(group_ops::internal_div),
1150 ),
1151 (
1152 "group_ops",
1153 "internal_hash_to",
1154 make_native!(group_ops::internal_hash_to),
1155 ),
1156 (
1157 "group_ops",
1158 "internal_multi_scalar_mul",
1159 make_native!(group_ops::internal_multi_scalar_mul),
1160 ),
1161 (
1162 "group_ops",
1163 "internal_pairing",
1164 make_native!(group_ops::internal_pairing),
1165 ),
1166 (
1167 "group_ops",
1168 "internal_convert",
1169 make_native!(group_ops::internal_convert),
1170 ),
1171 (
1172 "group_ops",
1173 "internal_sum",
1174 make_native!(group_ops::internal_sum),
1175 ),
1176 ("object", "delete_impl", make_native!(object::delete_impl)),
1177 ("object", "borrow_uid", make_native!(object::borrow_uid)),
1178 (
1179 "object",
1180 "record_new_uid",
1181 make_native!(object::record_new_uid),
1182 ),
1183 (
1184 "object",
1185 "record_new_uid_from_hash",
1186 make_native!(object::record_new_uid_from_hash),
1187 ),
1188 (
1189 "test_scenario",
1190 "take_from_address_by_id",
1191 make_native!(test_scenario::take_from_address_by_id),
1192 ),
1193 (
1194 "test_scenario",
1195 "most_recent_id_for_address",
1196 make_native!(test_scenario::most_recent_id_for_address),
1197 ),
1198 (
1199 "test_scenario",
1200 "was_taken_from_address",
1201 make_native!(test_scenario::was_taken_from_address),
1202 ),
1203 (
1204 "test_scenario",
1205 "take_immutable_by_id",
1206 make_native!(test_scenario::take_immutable_by_id),
1207 ),
1208 (
1209 "test_scenario",
1210 "most_recent_immutable_id",
1211 make_native!(test_scenario::most_recent_immutable_id),
1212 ),
1213 (
1214 "test_scenario",
1215 "was_taken_immutable",
1216 make_native!(test_scenario::was_taken_immutable),
1217 ),
1218 (
1219 "test_scenario",
1220 "take_shared_by_id",
1221 make_native!(test_scenario::take_shared_by_id),
1222 ),
1223 (
1224 "test_scenario",
1225 "most_recent_id_shared",
1226 make_native!(test_scenario::most_recent_id_shared),
1227 ),
1228 (
1229 "test_scenario",
1230 "was_taken_shared",
1231 make_native!(test_scenario::was_taken_shared),
1232 ),
1233 (
1234 "test_scenario",
1235 "end_transaction",
1236 make_native!(test_scenario::end_transaction),
1237 ),
1238 (
1239 "test_scenario",
1240 "ids_for_address",
1241 make_native!(test_scenario::ids_for_address),
1242 ),
1243 (
1244 "test_scenario",
1245 "allocate_receiving_ticket_for_object",
1246 make_native!(test_scenario::allocate_receiving_ticket_for_object),
1247 ),
1248 (
1249 "test_scenario",
1250 "deallocate_receiving_ticket_for_object",
1251 make_native!(test_scenario::deallocate_receiving_ticket_for_object),
1252 ),
1253 (
1254 "transfer",
1255 "transfer_impl",
1256 make_native!(transfer::transfer_internal),
1257 ),
1258 (
1259 "transfer",
1260 "party_transfer_impl",
1261 make_native!(transfer::party_transfer_internal),
1262 ),
1263 (
1264 "transfer",
1265 "freeze_object_impl",
1266 make_native!(transfer::freeze_object),
1267 ),
1268 (
1269 "transfer",
1270 "share_object_impl",
1271 make_native!(transfer::share_object),
1272 ),
1273 (
1274 "transfer",
1275 "receive_impl",
1276 make_native!(transfer::receive_object_internal),
1277 ),
1278 (
1279 "tx_context",
1280 "last_created_id",
1281 make_native!(tx_context::last_created_id),
1282 ),
1283 (
1284 "tx_context",
1285 "derive_id",
1286 make_native!(tx_context::derive_id),
1287 ),
1288 ("tx_context", "fresh_id", make_native!(tx_context::fresh_id)),
1289 (
1290 "tx_context",
1291 "native_sender",
1292 make_native!(tx_context::sender),
1293 ),
1294 (
1295 "tx_context",
1296 "native_epoch",
1297 make_native!(tx_context::epoch),
1298 ),
1299 (
1300 "tx_context",
1301 "native_epoch_timestamp_ms",
1302 make_native!(tx_context::epoch_timestamp_ms),
1303 ),
1304 (
1305 "tx_context",
1306 "native_sponsor",
1307 make_native!(tx_context::sponsor),
1308 ),
1309 ("tx_context", "native_rgp", make_native!(tx_context::rgp)),
1310 (
1311 "tx_context",
1312 "native_gas_price",
1313 make_native!(tx_context::gas_price),
1314 ),
1315 (
1316 "tx_context",
1317 "native_gas_budget",
1318 make_native!(tx_context::gas_budget),
1319 ),
1320 (
1321 "tx_context",
1322 "native_ids_created",
1323 make_native!(tx_context::ids_created),
1324 ),
1325 ("tx_context", "replace", make_native!(tx_context::replace)),
1326 (
1327 "types",
1328 "is_one_time_witness",
1329 make_native!(types::is_one_time_witness),
1330 ),
1331 (
1332 "test_utils",
1333 "create_one_time_witness",
1334 make_native!(test_utils::create_one_time_witness),
1335 ),
1336 (
1337 "random",
1338 "generate_rand_seed_for_testing",
1339 make_native!(random::generate_rand_seed_for_testing),
1340 ),
1341 (
1342 "zklogin_verified_id",
1343 "check_zklogin_id_internal",
1344 make_native!(zklogin::check_zklogin_id_internal),
1345 ),
1346 (
1347 "zklogin_verified_issuer",
1348 "check_zklogin_issuer_internal",
1349 make_native!(zklogin::check_zklogin_issuer_internal),
1350 ),
1351 (
1352 "poseidon",
1353 "poseidon_bn254_internal",
1354 make_native!(poseidon::poseidon_bn254_internal),
1355 ),
1356 (
1357 "protocol_config",
1358 "is_feature_enabled",
1359 make_native!(protocol_config::is_feature_enabled),
1360 ),
1361 (
1362 "vdf",
1363 "vdf_verify_internal",
1364 make_native!(vdf::vdf_verify_internal),
1365 ),
1366 (
1367 "vdf",
1368 "hash_to_input_internal",
1369 make_native!(vdf::hash_to_input_internal),
1370 ),
1371 (
1372 "ecdsa_k1",
1373 "secp256k1_sign",
1374 make_native!(ecdsa_k1::secp256k1_sign),
1375 ),
1376 (
1377 "ecdsa_k1",
1378 "secp256k1_keypair_from_seed",
1379 make_native!(ecdsa_k1::secp256k1_keypair_from_seed),
1380 ),
1381 (
1382 "nitro_attestation",
1383 "load_nitro_attestation_internal",
1384 make_native!(nitro_attestation::load_nitro_attestation_internal),
1385 ),
1386 (
1387 "rangeproofs",
1388 "verify_bulletproofs_ristretto255_internal",
1389 make_native!(rangeproofs::verify_bulletproofs_ristretto255),
1390 ),
1391 (
1392 "rangeproofs",
1393 "verify_bulletproofs_with_dst_ristretto255_internal",
1394 make_native!(rangeproofs::verify_bulletproofs_with_dst_ristretto255),
1395 ),
1396 ];
1397 let sui_framework_natives_iter =
1398 sui_framework_natives
1399 .iter()
1400 .cloned()
1401 .map(|(module_name, func_name, func)| {
1402 (
1403 SUI_FRAMEWORK_ADDRESS,
1404 Identifier::new(module_name).unwrap(),
1406 Identifier::new(func_name).unwrap(),
1407 func,
1408 )
1409 });
1410 let sui_system_natives: &[(&str, &str, NativeFunction)] = &[(
1411 "validator",
1412 "validate_metadata_bcs",
1413 make_native!(validator::validate_metadata_bcs),
1414 )];
1415 sui_system_natives
1416 .iter()
1417 .cloned()
1418 .map(|(module_name, func_name, func)| {
1419 (
1420 SUI_SYSTEM_ADDRESS,
1421 Identifier::new(module_name).unwrap(),
1423 Identifier::new(func_name).unwrap(),
1424 func,
1425 )
1426 })
1427 .chain(sui_framework_natives_iter)
1428 .chain(
1429 move_vm_runtime::natives::move_stdlib::stdlib_native_function_table(
1430 MOVE_STDLIB_ADDRESS,
1431 make_stdlib_gas_params_for_protocol_config(protocol_config),
1432 silent,
1433 ),
1434 )
1435 .collect()
1436}
1437
1438pub fn get_receiver_object_id(object: Value) -> Result<Value, PartialVMError> {
1441 get_nested_struct_field(object, &[0])
1442}
1443
1444pub fn get_object_id(object: Value) -> Result<Value, PartialVMError> {
1447 get_nested_struct_field(object, &[0, 0, 0])
1448}
1449
1450pub fn get_nested_struct_field(mut v: Value, offsets: &[usize]) -> Result<Value, PartialVMError> {
1453 for offset in offsets {
1454 v = get_nth_struct_field(v, *offset)?;
1455 }
1456 Ok(v)
1457}
1458
1459pub fn get_nth_struct_field(v: Value, n: usize) -> Result<Value, PartialVMError> {
1460 let mut itr = v.value_as::<Struct>()?.unpack();
1461 Ok(safe_unwrap!(itr.nth(n)))
1462}
1463
1464pub(crate) fn get_tag_and_layouts(
1466 context: &NativeContext,
1467 ty: &Type,
1468) -> PartialVMResult<Option<(StructTag, R::MoveTypeLayout, A::MoveTypeLayout)>> {
1469 let tag = match context.type_to_type_tag(ty)? {
1470 TypeTag::Struct(s) => s,
1471 _ => {
1472 return Err(
1473 PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
1474 .with_message("Sui verifier guarantees this is a struct".to_string()),
1475 );
1476 }
1477 };
1478 let Some(layout) = context.type_to_type_layout(ty)? else {
1479 return Ok(None);
1480 };
1481 let Some(annotated_layout) = context.type_to_fully_annotated_layout(ty)? else {
1482 return Ok(None);
1483 };
1484 Ok(Some((*tag, layout, annotated_layout)))
1485}
1486
1487#[macro_export]
1488macro_rules! make_native {
1489 ($native: expr) => {
1490 Arc::new(
1491 move |context, ty_args, args| -> PartialVMResult<NativeResult> {
1492 $native(context, ty_args, args)
1493 },
1494 )
1495 };
1496}
1497
1498#[macro_export]
1499macro_rules! get_extension {
1500 ($context: expr, $ext: ty) => {
1501 $context.extensions().get::<$ext>()
1502 };
1503 ($context: expr) => {
1504 $context.extensions().get()
1505 };
1506}
1507
1508#[macro_export]
1509macro_rules! get_extension_mut {
1510 ($context: expr, $ext: ty) => {
1511 $context.extensions_mut().get_mut::<$ext>()
1512 };
1513 ($context: expr) => {
1514 $context.extensions_mut().get_mut()
1515 };
1516}
1517
1518#[macro_export]
1519macro_rules! charge_cache_or_load_gas {
1520 ($context:ident, $cache_info:expr) => {{
1521 use $crate::object_runtime::object_store::CacheInfo;
1522 match $cache_info {
1523 CacheInfo::CachedObject | CacheInfo::CachedValue => (),
1524 CacheInfo::Loaded(bytes_opt) => {
1525 let config = get_extension!($context, ObjectRuntime)?.protocol_config;
1526 if config.object_runtime_charge_cache_load_gas() {
1527 let bytes = bytes_opt.unwrap_or(0).max(1);
1528 native_charge_gas_early_exit!($context, InternalGas::new(bytes as u64));
1529 }
1530 }
1531 }
1532 }};
1533}
1534
1535pub(crate) fn legacy_test_cost() -> InternalGas {
1536 InternalGas::new(0)
1537}
1538
1539pub(crate) fn abstract_size(
1540 _protocol_config: &ProtocolConfig,
1541 v: &Value,
1542) -> PartialVMResult<AbstractMemorySize> {
1543 v.abstract_memory_size(&SizeConfig {
1544 include_vector_size: true,
1545 traverse_references: false,
1546 })
1547}