Skip to content

Commit 294045f

Browse files
committed
[6/n][vm-rewrite][sui-execution] Update object runtime to use type tags 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.
1 parent 2f9e925 commit 294045f

28 files changed

+387
-286
lines changed

sui-execution/latest/sui-move-natives/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ fastcrypto-vdf.workspace = true
1919
fastcrypto.workspace = true
2020
move-binary-format.workspace = true
2121
move-core-types.workspace = true
22-
move-vm-types.workspace = true
2322

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

2725
sui-protocol-config.workspace = true

sui-execution/latest/sui-move-natives/src/address.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
use crate::NativesCostTable;
55
use move_binary_format::errors::PartialVMResult;
66
use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas, u256::U256};
7-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
8-
use move_vm_types::{
9-
loaded_data::runtime_types::Type, natives::function::NativeResult, pop_arg, values::Value,
7+
use move_vm_runtime::{
8+
execution::{values::Value, Type},
9+
natives::functions::NativeResult,
10+
pop_arg,
1011
};
12+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
1113
use smallvec::smallvec;
1214
use std::collections::VecDeque;
1315

sui-execution/latest/sui-move-natives/src/config.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ use move_core_types::{
88
runtime_value as R, vm_status::StatusCode,
99
};
1010
use move_vm_runtime::native_charge_gas_early_exit;
11-
use move_vm_runtime::native_functions::NativeContext;
12-
use move_vm_types::{
13-
loaded_data::runtime_types::Type,
14-
natives::function::NativeResult,
11+
use move_vm_runtime::natives::extensions::NativeContextMut;
12+
use move_vm_runtime::natives::functions::NativeContext;
13+
use move_vm_runtime::{
14+
execution::{
15+
values::{Struct, Value, Vector},
16+
Type,
17+
},
18+
natives::functions::NativeResult,
1519
pop_arg,
16-
values::{Struct, Value, Vector},
1720
};
1821
use smallvec::smallvec;
22+
use std::cell::RefMut;
1923
use std::collections::VecDeque;
2024
use sui_types::{base_types::MoveObjectType, TypeTag};
2125
use tracing::{error, instrument};
@@ -83,11 +87,13 @@ pub fn read_setting_impl(
8387
E_BCS_SERIALIZATION_FAILURE,
8488
));
8589
};
86-
let object_runtime: &mut ObjectRuntime = context.extensions_mut().get_mut();
90+
let object_runtime: RefMut<ObjectRuntime> = context
91+
.extensions_mut()
92+
.get::<NativeContextMut<ObjectRuntime>>()
93+
.get_mut();
8794

8895
let read_value_opt = consistent_value_before_current_epoch(
8996
object_runtime,
90-
&field_setting_ty,
9197
field_setting_tag,
9298
&field_setting_layout,
9399
&setting_value_ty,
@@ -110,8 +116,7 @@ pub fn read_setting_impl(
110116
}
111117

112118
fn consistent_value_before_current_epoch(
113-
object_runtime: &mut ObjectRuntime,
114-
field_setting_ty: &Type,
119+
mut object_runtime: RefMut<ObjectRuntime>,
115120
field_setting_tag: StructTag,
116121
field_setting_layout: &R::MoveTypeLayout,
117122
_setting_value_ty: &Type,
@@ -125,7 +130,6 @@ fn consistent_value_before_current_epoch(
125130
let Some(field) = object_runtime.config_setting_unsequenced_read(
126131
config_addr.into(),
127132
name_df_addr.into(),
128-
field_setting_ty,
129133
field_setting_layout,
130134
&field_setting_obj_ty,
131135
) else {
@@ -150,8 +154,8 @@ fn consistent_value_before_current_epoch(
150154
let [newer_value_epoch, newer_value, older_value_opt]: [Value; 3] = unpack_struct(data)?;
151155
let newer_value_epoch: u64 = newer_value_epoch.value_as()?;
152156
debug_assert!(
153-
unpack_option(newer_value.copy_value()?, value_ty)?.is_some()
154-
|| unpack_option(older_value_opt.copy_value()?, value_ty)?.is_some()
157+
unpack_option(newer_value.copy_value(), value_ty)?.is_some()
158+
|| unpack_option(older_value_opt.copy_value(), value_ty)?.is_some()
155159
);
156160
Ok(if current_epoch > newer_value_epoch {
157161
newer_value

sui-execution/latest/sui-move-natives/src/crypto/bls12381.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use fastcrypto::{
66
};
77
use move_binary_format::errors::PartialVMResult;
88
use move_core_types::gas_algebra::InternalGas;
9-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
10-
use move_vm_types::{
11-
loaded_data::runtime_types::Type,
12-
natives::function::NativeResult,
9+
use move_vm_runtime::{
10+
execution::{
11+
values::{Value, VectorRef},
12+
Type,
13+
},
14+
natives::functions::NativeResult,
1315
pop_arg,
14-
values::{Value, VectorRef},
1516
};
17+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
1618
use smallvec::smallvec;
1719
use std::collections::VecDeque;
1820

sui-execution/latest/sui-move-natives/src/crypto/ecdsa_k1.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ use fastcrypto::{
1414
};
1515
use move_binary_format::errors::PartialVMResult;
1616
use move_core_types::gas_algebra::InternalGas;
17-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
18-
use move_vm_types::{
19-
loaded_data::runtime_types::Type,
20-
natives::function::NativeResult,
17+
use move_vm_runtime::{
18+
execution::{
19+
values::{self, Value, VectorRef},
20+
Type,
21+
},
22+
natives::functions::NativeResult,
2123
pop_arg,
22-
values::{self, Value, VectorRef},
2324
};
25+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
2426
use rand::rngs::StdRng;
2527
use rand::SeedableRng;
2628
use smallvec::smallvec;

sui-execution/latest/sui-move-natives/src/crypto/ecdsa_r1.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ use fastcrypto::{
1313
use move_binary_format::errors::PartialVMResult;
1414
use move_core_types::gas_algebra::InternalGas;
1515
use move_vm_runtime::native_charge_gas_early_exit;
16-
use move_vm_runtime::native_functions::NativeContext;
17-
use move_vm_types::{
18-
loaded_data::runtime_types::Type,
19-
natives::function::NativeResult,
16+
use move_vm_runtime::natives::functions::NativeContext;
17+
use move_vm_runtime::{
18+
execution::{
19+
values::{Value, VectorRef},
20+
Type,
21+
},
22+
natives::functions::NativeResult,
2023
pop_arg,
21-
values::{Value, VectorRef},
2224
};
2325
use smallvec::smallvec;
2426
use std::collections::VecDeque;

sui-execution/latest/sui-move-natives/src/crypto/ecvrf.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ use fastcrypto::vrf::ecvrf::{ECVRFProof, ECVRFPublicKey};
55
use fastcrypto::vrf::VRFProof;
66
use move_binary_format::errors::PartialVMResult;
77
use move_core_types::gas_algebra::InternalGas;
8-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
9-
use move_vm_types::{
10-
loaded_data::runtime_types::Type,
11-
natives::function::NativeResult,
8+
use move_vm_runtime::{
9+
execution::{
10+
values::{Value, VectorRef},
11+
Type,
12+
},
13+
natives::functions::NativeResult,
1214
pop_arg,
13-
values::{Value, VectorRef},
1415
};
16+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
1517
use smallvec::smallvec;
1618
use std::collections::VecDeque;
1719

sui-execution/latest/sui-move-natives/src/crypto/ed25519.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ use fastcrypto::{
77
};
88
use move_binary_format::errors::PartialVMResult;
99
use move_core_types::gas_algebra::InternalGas;
10-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
11-
use move_vm_types::{
12-
loaded_data::runtime_types::Type,
13-
natives::function::NativeResult,
10+
use move_vm_runtime::{
11+
execution::{
12+
values::{Value, VectorRef},
13+
Type,
14+
},
15+
natives::functions::NativeResult,
1416
pop_arg,
15-
values::{Value, VectorRef},
1617
};
18+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
1719
use smallvec::smallvec;
1820
use std::collections::VecDeque;
1921

sui-execution/latest/sui-move-natives/src/crypto/groth16.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
use crate::{object_runtime::ObjectRuntime, NativesCostTable};
44
use move_binary_format::errors::PartialVMResult;
55
use move_core_types::gas_algebra::InternalGas;
6-
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
7-
use move_vm_types::{
8-
loaded_data::runtime_types::Type,
9-
natives::function::NativeResult,
6+
use move_vm_runtime::{
7+
execution::{
8+
values::{self, Value, VectorRef},
9+
Type,
10+
},
11+
natives::functions::NativeResult,
1012
pop_arg,
11-
values::{self, Value, VectorRef},
1213
};
14+
use move_vm_runtime::{native_charge_gas_early_exit, natives::functions::NativeContext};
1315
use smallvec::smallvec;
1416
use std::collections::VecDeque;
1517

sui-execution/latest/sui-move-natives/src/crypto/group_ops.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ use move_binary_format::errors::{PartialVMError, PartialVMResult};
1212
use move_core_types::gas_algebra::InternalGas;
1313
use move_core_types::vm_status::StatusCode;
1414
use move_vm_runtime::native_charge_gas_early_exit;
15-
use move_vm_runtime::native_functions::NativeContext;
16-
use move_vm_types::{
17-
loaded_data::runtime_types::Type,
18-
natives::function::NativeResult,
15+
use move_vm_runtime::natives::functions::NativeContext;
16+
use move_vm_runtime::{
17+
execution::{
18+
values::{Value, VectorRef},
19+
Type,
20+
},
21+
natives::functions::NativeResult,
1922
pop_arg,
20-
values::{Value, VectorRef},
2123
};
2224
use smallvec::smallvec;
2325
use std::collections::VecDeque;

0 commit comments

Comments
 (0)