Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Define configurable limits for struct and function instantiations #982

Draft
wants to merge 1 commit into
base: sui-move
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ fn big_signature_test() {
max_fields_in_struct: Some(30),
max_function_definitions: Some(1000),
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
max_type_instantiation_size: Some(128),
max_function_instantiation_size: Some(128),
},
&module,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn test_vec_pack() {
max_fields_in_struct: Some(30),
max_function_definitions: Some(1000),
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
..Default::default()
},
&m,
)
Expand Down
7 changes: 7 additions & 0 deletions language/move-bytecode-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub struct VerifierConfig {
pub max_fields_in_struct: Option<usize>,
pub max_function_definitions: Option<usize>,
pub max_constant_vector_len: u64,
// Max number of nodes which are allowed when instantiating a generic type.
// This does not include field types of structs.
pub max_type_instantiation_size: Option<usize>,
// Max number of nodes which are allowed when instantiating a generic function.
pub max_function_instantiation_size: Option<usize>,
}

/// Helper for a "canonical" verification of a module.
Expand Down Expand Up @@ -144,6 +149,8 @@ impl Default for VerifierConfig {
max_function_definitions: None,
// Max len of vector constant
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
max_type_instantiation_size: None,
max_function_instantiation_size: None,
}
}
}
3 changes: 3 additions & 0 deletions language/move-vm/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.52"
once_cell = "1.7.2"
tempfile = "3.2.0"
memory-stats = "1.0.0"

Expand All @@ -26,6 +27,8 @@ move-vm-test-utils = { path = "../test-utils" }
move-stdlib = { path = "../../move-stdlib" }
move-table-extension = { path = "../../extensions/move-table-extension", optional = true }

bcs.workspace = true

[features]
default = []
table-extension = [
Expand Down
2,788 changes: 2,788 additions & 0 deletions language/move-vm/integration-tests/src/tests/limits_tests.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions language/move-vm/integration-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod function_arg_tests;
mod instantiation_tests;
mod invariant_violation_tests;
mod leak_tests;
mod limits_tests;
mod loader_tests;
mod mutated_accounts_tests;
mod nested_loop_tests;
Expand Down
5 changes: 3 additions & 2 deletions language/move-vm/runtime/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ impl Frame {
interpreter.operand_stack.push_ty(output_ty)?;
}
Bytecode::PackGeneric(idx) => {
let field_count = resolver.field_instantiation_count(*idx);
let field_count = resolver.field_instantiation_count(*idx, ty_args)?;
let args_ty = resolver.instantiate_generic_struct_fields(*idx, ty_args)?;
let output_ty = resolver.instantiate_generic_type(*idx, ty_args)?;
let ability = resolver.loader().abilities(&output_ty)?;
Expand Down Expand Up @@ -1851,7 +1851,8 @@ impl Frame {
.push(Value::struct_(Struct::pack(args)))?;
}
Bytecode::PackGeneric(si_idx) => {
let field_count = resolver.field_instantiation_count(*si_idx);
let field_count =
resolver.field_instantiation_count(*si_idx, self.ty_args())?;
gas_meter.charge_pack(
true,
interpreter.operand_stack.last_n(field_count as usize)?,
Expand Down
Loading