Skip to content

Commit

Permalink
Move values cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dariorussi authored and ebmifa committed Jun 1, 2023
1 parent 6f10a66 commit 8b68151
Show file tree
Hide file tree
Showing 15 changed files with 716 additions and 37 deletions.
1 change: 1 addition & 0 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@
"max_move_package_size": {
"u64": "102400"
},
"max_move_value_depth": null,
"max_move_vector_len": {
"u64": "262144"
},
Expand Down
11 changes: 10 additions & 1 deletion crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const MAX_PROTOCOL_VERSION: u64 = 11;
// `max_meter_ticks_per_module` limits each from 6_000_000 to 16_000_000. sui-system
// framework changes.
// Version 11: Introduce `std::type_name::get_with_original_ids` to the system frameworks.
// Bound max depth of values within the VM.

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -343,6 +344,9 @@ pub struct ProtocolConfig {
/// Maximum length of an `Identifier` in Move. Enforced by the bytecode verifier at signing.
max_move_identifier_len: Option<u64>,

/// Maximum depth of a Move value within the VM.
max_move_value_depth: Option<u64>,

/// Maximum number of back edges in Move function. Enforced by the bytecode verifier at signing.
max_back_edges_per_function: Option<u64>,

Expand Down Expand Up @@ -1049,6 +1053,7 @@ impl ProtocolConfig {

// Limits the length of a Move identifier
max_move_identifier_len: None,
max_move_value_depth: None,

// When adding a new constant, set it to None in the earliest version, like this:
// new_constant: None,
Expand Down Expand Up @@ -1130,7 +1135,11 @@ impl ProtocolConfig {
cfg.max_meter_ticks_per_module = Some(16_000_000);
cfg
}
11 => Self::get_for_version_impl(version - 1),
11 => {
let mut cfg = Self::get_for_version_impl(version - 1);
cfg.max_move_value_depth = Some(128);
cfg
}
// Use this template when making changes:
//
// // modify an existing constant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ max_num_transferred_move_object_ids_system_tx: 32768
max_event_emit_size: 256000
max_move_vector_len: 262144
max_move_identifier_len: 128
max_move_value_depth: 128
max_back_edges_per_function: 10000
max_back_edges_per_module: 10000
max_verifier_meter_ticks_per_function: 16000000
Expand Down
5 changes: 5 additions & 0 deletions external-crates/move/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ debug = true
[profile.dev]
debug = true

[profile.test.package.move-vm-integration-tests]
# opt-level 2 for move-compiler reduces the size of some of its
# (recursive) stack frames by up to 10x, avoiding stack overflows.
opt-level = 3

# use release settings to reduce memory pressure in the linking step in CI
[profile.ci]
inherits = "test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module std::event_tests {
}

#[test(s = @0x42)]
#[expected_failure(abort_code = 0, location = std::event)]
#[expected_failure] // VM_MAX_VALUE_DEPTH_REACHED
fun test_event_129(s: signer) acquires MyEvent {
event_129(&s);
}
Expand Down
2 changes: 1 addition & 1 deletion external-crates/move/move-stdlib/tests/bcs_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module std::bcs_tests {
}

#[test]
#[expected_failure(abort_code = 453, location = std::bcs)]
#[expected_failure] // VM_MAX_VALUE_DEPTH_REACHED
fun encode_129() {
bcs::to_bytes(&Box { x: box127(true) });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
address 0x2 {
module A {
struct S has copy, drop {
f1: 0x2::B::S,
f2: 0x2::C::S,
}

struct Box<T> has copy, drop, store { x: T }
struct Box3<T> has copy, drop, store { x: Box<Box<T>> }
struct Box7<T> has copy, drop, store { x: Box3<Box3<T>> }
struct Box15<T> has copy, drop, store { x: Box7<Box7<T>> }
struct Box31<T> has copy, drop, store { x: Box15<Box15<T>> }
struct Box63<T> has copy, drop, store { x: Box31<Box31<T>> }
struct Box127<T> has copy, drop, store { x: Box63<Box63<T>> }
}

module B {
struct S has copy, drop {
f1: u64,
f2: u128,
}
}
module C {
struct S has copy, drop {
f1: address,
f2: bool,
}
}

module D {
struct S has copy, drop {
f1: 0x2::B::S,
}
}

module E {
struct S<T> has copy, drop {
f1: 0x2::F::S<T>,
f2: u64,
}
}

module F {
struct S<T> has copy, drop {
f1: T,
f2: u64,
}
}

module G {
struct S<A, B> has copy, drop {
f1: 0x2::H::S<B, A>,
f2: u64,
}
}

module H {
struct S<A, B> has copy, drop {
f1: 0x2::F::S<A>,
f2: 0x2::E::S<B>,
f3: 0x2::E::S<0x2::F::S<B>>,
f4: A,
f5: B,
f6: u64,
}
}

module I {
struct S<A, B> {
f1: F<A>,
f2: E<B>,
f3: E<F<B>>,
f4: E<F<F<B>>>,
f5: E<F<F<LL<A, B>>>>,
f6: A,
f7: B,
f8: u64,
}

struct E<T> {
f1: F<T>,
f2: u64,
}

struct F<T> {
f1: T,
f2: u64,
}

struct H<T> {
f1: T,
f2: u64,
}

struct G<phantom T> {
f: H<u64>,
}

struct L<T> {
g1: G<T>,
g2: H<T>,
}

struct LL<phantom A, B> {
g1: G<A>,
g2: H<B>,
}

struct N<phantom Y> {
f: u64
}
}
}
Loading

0 comments on commit 8b68151

Please sign in to comment.