Skip to content

Commit

Permalink
Bound Move vector length & update move ptr (MystenLabs#8897)
Browse files Browse the repository at this point in the history
## Description 

Updates move ptr and bounds the length of a vector in Move

## Test Plan 

Adapter transactional tests

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [x] necessitate either a data wipe or data migration

### Release notes
Move vectors are now limited to `262144` length
  • Loading branch information
oxade authored Mar 6, 2023
1 parent 95a65b6 commit 5afba38
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 121 deletions.
6 changes: 3 additions & 3 deletions .config/hakari.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ workspace-members = [ "sui-move" ]
third-party = [
## Exclude the 'move-unit-test' crate in order to ensure that the 'testing'
# feature isn't enabled in the workspace-hack
{ name = "move-unit-test", git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" },
{ name = "move-cli", git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" },
{ name = "move-transactional-test-runner", git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" },
{ name = "move-unit-test", git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" },
{ name = "move-cli", git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" },
{ name = "move-transactional-test-runner", git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" },
]

[final-excludes]
Expand Down
76 changes: 38 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,26 @@ opt-level = 1
tokio = "1.24.1"

# Move dependencies
move-binary-format = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-cli = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-compiler = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-core-types = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d", features = ["address32"] }
move-disassembler = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-package = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-stdlib = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-unit-test = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-vm-test-utils = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-command-line-common = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-transactional-test-runner = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-ir-types = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-prover = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-prover-boogie-backend = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-stackless-bytecode = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-symbol-pool = { git = "https://github.com/move-language/move", rev = "299784312ca360f970c0e75f7a08116d7731ad1d" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-cli = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-compiler = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-core-types = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f", features = ["address32"] }
move-disassembler = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-package = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-stdlib = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-unit-test = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-vm-test-utils = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-command-line-common = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-transactional-test-runner = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-ir-types = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-prover = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-prover-boogie-backend = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-stackless-bytecode = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }
move-symbol-pool = { git = "https://github.com/move-language/move", rev = "8729cf2445696cb29f1e0ca06df7d09cf3c2c55f" }

fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "9cae043d0821662c075fd054c5c5523dcb20b5fb" }
fastcrypto-zkp = { git = "https://github.com/MystenLabs/fastcrypto", rev = "9cae043d0821662c075fd054c5c5523dcb20b5fb", package = "fastcrypto-zkp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ module Test::M1 {
// delete below delete count limit should succeed
//# run Test::M1::delete_n_ids --args 256

// run at run count limit should succeed
// delete at delete count limit should succeed
//# run Test::M1::delete_n_ids --args 2048

// run above run count limit should fail
// delete above delete count limit should fail
//# run Test::M1::delete_n_ids --args 2049

// run above run count limit should fail
// delete above delete count limit should fail
//# run Test::M1::delete_n_ids --args 4096
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ written: object(109)

task 7 'run'. lines 75-75:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::event::emit (function index 0) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: MovePrimitiveRuntimeError(Some(MoveLocation { module: ModuleId { address: sui, name: Identifier("event") }, function: 0, instruction: 0, function_name: Some("emit") })), source: Some(VMError { major_status: MEMORY_LIMIT_EXCEEDED, sub_status: Some(1), message: Some("Emitting event of size 300046 bytes. Limit is 262144 bytes."), exec_state: None, location: Module(ModuleId { address: sui, name: Identifier("event") }), indices: [], offsets: [(FunctionDefinitionIndex(0), 0)] }), command: Some(0) } }
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: MovePrimitiveRuntimeError(Some(MoveLocation { module: ModuleId { address: sui, name: Identifier("event") }, function: 0, instruction: 0, function_name: Some("emit") })), source: Some(VMError { major_status: MEMORY_LIMIT_EXCEEDED, sub_status: Some(1), message: Some("Emitting event of size 259046 bytes. Limit is 256000 bytes."), exec_state: None, location: Module(ModuleId { address: sui, name: Identifier("event") }), indices: [], offsets: [(FunctionDefinitionIndex(0), 0)] }), command: Some(0) } }
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ module Test::M1 {
//# run Test::M1::emit_object_with_approx_size --args 200000

// emit above event size limit should fail
//# run Test::M1::emit_object_with_approx_size --args 300000
//# run Test::M1::emit_object_with_approx_size --args 259000
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
processed 6 tasks

task 1 'publish'. lines 8-30:
created: object(104)
written: object(103)

task 2 'run'. lines 31-33:
written: object(105)

task 3 'run'. lines 34-36:
written: object(106)

task 4 'run'. lines 37-39:
written: object(107)

task 5 'run'. lines 40-40:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: Test::M1::push_n_items (function index 0) at offset 11. Arithmetic error, stack overflow, max value depth, etc.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: MovePrimitiveRuntimeError(Some(MoveLocation { module: ModuleId { address: Test, name: Identifier("M1") }, function: 0, instruction: 11, function_name: Some("push_n_items") })), source: Some(VMError { major_status: VECTOR_OPERATION_ERROR, sub_status: Some(4), message: Some("vector size limit is 262144"), exec_state: Some(ExecutionState { stack_trace: [] }), location: Module(ModuleId { address: Test, name: Identifier("M1") }), indices: [], offsets: [(FunctionDefinitionIndex(0), 11)] }), command: Some(0) } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Test limts on length of vectors

//# init --addresses Test=0x0

//# publish

/// Test vector length limits enforced
module Test::M1 {
use std::vector;

public entry fun push_n_items(n: u64) {
let v: vector<u64> = vector::empty();
let i = 0;
while (i < n) {
vector::push_back(&mut v, i);
i = i + 1;
};
i = 0;
while (i < n) {
let _ = vector::pop_back(&mut v);
i = i + 1;
};
vector::destroy_empty(v);
}
}

// push below ven len limit should succeed
//# run Test::M1::push_n_items --args 1

// push below vec len limit should succeed
//# run Test::M1::push_n_items --args 256

// run at vec len limit should succeed
//# run Test::M1::push_n_items --args 262144

// run above vec len limit should fail
//# run Test::M1::push_n_items --args 262145
6 changes: 5 additions & 1 deletion crates/sui-adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use move_core_types::{
};
pub use move_vm_runtime::move_vm::MoveVM;
use move_vm_runtime::{
config::VMConfig,
config::{VMConfig, VMRuntimeLimitsConfig},
native_extensions::NativeContextExtensions,
native_functions::NativeFunctionTable,
session::{SerializedReturnValues, Session},
Expand Down Expand Up @@ -81,9 +81,13 @@ pub fn new_move_vm(
max_fields_in_struct: Some(protocol_config.max_fields_in_struct()),
max_function_definitions: Some(protocol_config.max_function_definitions()),
max_struct_definitions: Some(protocol_config.max_struct_definitions()),
max_constant_vector_len: protocol_config.max_move_vector_len(),
},
max_binary_format_version: protocol_config.move_binary_format_version(),
paranoid_type_checks: false,
runtime_limits_config: VMRuntimeLimitsConfig {
vector_len_max: protocol_config.max_move_vector_len(),
},
},
)
.map_err(|_| SuiError::ExecutionInvariantViolation)
Expand Down
9 changes: 8 additions & 1 deletion crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ pub struct ProtocolConfig {
/// Maximum size of a Move user event. Enforced by the VM during execution.
max_event_emit_size: Option<u64>,

/// Maximum length of a vector in Move. Enforced by the VM during execution, and for constants, by the verifier.
max_move_vector_len: Option<u64>,

// === Execution gas costs ====
// note: Option<per-instruction and native function gas costs live in the sui-cost-tables crate
/// Base cost for any Sui transaction
Expand Down Expand Up @@ -413,6 +416,9 @@ impl ProtocolConfig {
pub fn max_event_emit_size(&self) -> u64 {
self.max_event_emit_size.expect(CONSTANT_ERR_MSG)
}
pub fn max_move_vector_len(&self) -> u64 {
self.max_move_vector_len.expect(CONSTANT_ERR_MSG)
}
pub fn base_tx_cost_fixed(&self) -> u64 {
self.base_tx_cost_fixed.expect(CONSTANT_ERR_MSG)
}
Expand Down Expand Up @@ -632,7 +638,8 @@ impl ProtocolConfig {
max_num_new_move_object_ids: Some(2048),
max_num_deleted_move_object_ids: Some(2048),
max_num_transfered_move_object_ids: Some(2048),
max_event_emit_size: Some(256 * 1024),
max_event_emit_size: Some(250 * 1024),
max_move_vector_len: Some(256 * 1024),
base_tx_cost_fixed: Some(110_000),
package_publish_cost_fixed: Some(1_000),
base_tx_cost_per_byte: Some(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ max_num_event_emit: 256
max_num_new_move_object_ids: 2048
max_num_deleted_move_object_ids: 2048
max_num_transfered_move_object_ids: 2048
max_event_emit_size: 262144
max_event_emit_size: 256000
max_move_vector_len: 262144
base_tx_cost_fixed: 110000
package_publish_cost_fixed: 1000
base_tx_cost_per_byte: 0
Expand Down
Loading

0 comments on commit 5afba38

Please sign in to comment.