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