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