Skip to content

Commit

Permalink
[6/n][vm-rewrite][sui-execution] Update object runtime to use type ta…
Browse files Browse the repository at this point in the history
…gs instead of runtime VM types.

Since the VM instance no longer will live across commands/the entire
lifetime of the object runtime, this replaces all VM runtime `Type`s
with `TypeTag`s or `MoveObjectType`s where appropriate. This also
updates the natives and runtime to handle the new
`NativeContextExtensions` model.

NB: The code in the PR may not be working as future PRs will build on top of
this.
  • Loading branch information
tzakian committed Feb 3, 2025
1 parent 2f24850 commit 489397b
Show file tree
Hide file tree
Showing 28 changed files with 388 additions and 286 deletions.
2 changes: 0 additions & 2 deletions sui-execution/latest/sui-move-natives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ fastcrypto-vdf.workspace = true
fastcrypto.workspace = true
move-binary-format.workspace = true
move-core-types.workspace = true
move-vm-types.workspace = true

move-stdlib-natives = { path = "../../../external-crates/move/crates/move-stdlib-natives" }
move-vm-runtime = { path = "../../../external-crates/move/crates/move-vm-runtime" }

sui-protocol-config.workspace = true
Expand Down
8 changes: 5 additions & 3 deletions sui-execution/latest/sui-move-natives/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use crate::NativesCostTable;
use move_binary_format::errors::PartialVMResult;
use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas, u256::U256};
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type, natives::function::NativeResult, pop_arg, values::Value,
use move_vm_runtime::{
execution::{values::Value, Type},
natives::functions::NativeResult,
pop_arg,
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
29 changes: 17 additions & 12 deletions sui-execution/latest/sui-move-natives/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ use move_core_types::{
runtime_value as R, vm_status::StatusCode,
};
use move_vm_runtime::native_charge_gas_early_exit;
use move_vm_runtime::native_functions::NativeContext;
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::natives::extensions::NativeContextMut;
use move_vm_runtime::natives::functions::NativeContext;
use move_vm_runtime::{
execution::{
values::{Struct, Value, Vector},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Struct, Value, Vector},
};
use smallvec::smallvec;
use std::cell::RefMut;
use std::collections::VecDeque;
use sui_types::{base_types::MoveObjectType, TypeTag};
use tracing::{error, instrument};
Expand Down Expand Up @@ -83,11 +87,14 @@ pub fn read_setting_impl(
E_BCS_SERIALIZATION_FAILURE,
));
};
let object_runtime: &mut ObjectRuntime = context.extensions_mut().get_mut();
// let object_runtime: &NativeContextMut<ObjectRuntime>
let object_runtime: std::cell::RefMut<'_, ObjectRuntime<'_>> = context
.extensions_mut()
.get::<NativeContextMut<ObjectRuntime>>()
.get_mut();

let read_value_opt = consistent_value_before_current_epoch(
object_runtime,
&field_setting_ty,
field_setting_tag,
&field_setting_layout,
&setting_value_ty,
Expand All @@ -110,8 +117,7 @@ pub fn read_setting_impl(
}

fn consistent_value_before_current_epoch(
object_runtime: &mut ObjectRuntime,
field_setting_ty: &Type,
mut object_runtime: RefMut<'_, ObjectRuntime<'_>>,
field_setting_tag: StructTag,
field_setting_layout: &R::MoveTypeLayout,
_setting_value_ty: &Type,
Expand All @@ -125,7 +131,6 @@ fn consistent_value_before_current_epoch(
let Some(field) = object_runtime.config_setting_unsequenced_read(
config_addr.into(),
name_df_addr.into(),
field_setting_ty,
field_setting_layout,
&field_setting_obj_ty,
) else {
Expand All @@ -150,8 +155,8 @@ fn consistent_value_before_current_epoch(
let [newer_value_epoch, newer_value, older_value_opt]: [Value; 3] = unpack_struct(data)?;
let newer_value_epoch: u64 = newer_value_epoch.value_as()?;
debug_assert!(
unpack_option(newer_value.copy_value()?, value_ty)?.is_some()
|| unpack_option(older_value_opt.copy_value()?, value_ty)?.is_some()
unpack_option(newer_value.copy_value(), value_ty)?.is_some()
|| unpack_option(older_value_opt.copy_value(), value_ty)?.is_some()
);
Ok(if current_epoch > newer_value_epoch {
newer_value
Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use fastcrypto::{
};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/ecdsa_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ use fastcrypto::{
};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{self, Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{self, Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use rand::rngs::StdRng;
use rand::SeedableRng;
use smallvec::smallvec;
Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/ecdsa_r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ use fastcrypto::{
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::native_charge_gas_early_exit;
use move_vm_runtime::native_functions::NativeContext;
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::natives::functions::NativeContext;
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use smallvec::smallvec;
use std::collections::VecDeque;
Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/ecvrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use fastcrypto::vrf::ecvrf::{ECVRFProof, ECVRFPublicKey};
use fastcrypto::vrf::VRFProof;
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use fastcrypto::{
};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
use crate::{object_runtime::ObjectRuntime, NativesCostTable};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{self, Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{self, Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/group_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ use move_binary_format::errors::{PartialVMError, PartialVMResult};
use move_core_types::gas_algebra::InternalGas;
use move_core_types::vm_status::StatusCode;
use move_vm_runtime::native_charge_gas_early_exit;
use move_vm_runtime::native_functions::NativeContext;
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::natives::functions::NativeContext;
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use smallvec::smallvec;
use std::collections::VecDeque;
Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use crate::NativesCostTable;
use fastcrypto::hash::{Blake2b256, HashFunction, Keccak256};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::{collections::VecDeque, ops::Mul};

Expand Down
12 changes: 7 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use crate::NativesCostTable;
use fastcrypto::{hmac, traits::ToFromBytes};
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::NativeResult,
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
13 changes: 7 additions & 6 deletions sui-execution/latest/sui-move-natives/src/crypto/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use fastcrypto_zkp::bn254::poseidon::poseidon_bytes;
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_core_types::vm_status::StatusCode;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::natives::function::PartialVMError;
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::{NativeResult, PartialVMError},
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;
use std::ops::Mul;
Expand Down
13 changes: 7 additions & 6 deletions sui-execution/latest/sui-move-natives/src/crypto/vdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use fastcrypto_vdf::vdf::VDF;
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::InternalGas;
use move_core_types::vm_status::StatusCode;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::natives::function::PartialVMError;
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::{NativeResult, PartialVMError},
pop_arg,
values::{Value, VectorRef},
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
13 changes: 8 additions & 5 deletions sui-execution/latest/sui-move-natives/src/crypto/zklogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ use move_core_types::account_address::AccountAddress;
use move_core_types::gas_algebra::InternalGas;
use move_core_types::u256::U256;
use move_core_types::vm_status::StatusCode;
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::natives::function::PartialVMError;
use move_vm_types::values::VectorRef;
use move_vm_types::{
loaded_data::runtime_types::Type, natives::function::NativeResult, pop_arg, values::Value,
use move_vm_runtime::{
execution::{
values::{Value, VectorRef},
Type,
},
natives::functions::{NativeResult, PartialVMError},
pop_arg,
};
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
use smallvec::smallvec;
use std::collections::VecDeque;

Expand Down
Loading

0 comments on commit 489397b

Please sign in to comment.