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