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

Commit 05551a1

Browse files
committed
Define configurable limits for struct and function instantiations
1 parent 0ce8e4b commit 05551a1

File tree

10 files changed

+2981
-70
lines changed

10 files changed

+2981
-70
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/signature_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ fn big_signature_test() {
230230
max_fields_in_struct: Some(30),
231231
max_function_definitions: Some(1000),
232232
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
233+
max_type_instantiation_size: Some(128),
234+
max_function_instantiation_size: Some(128),
233235
},
234236
&module,
235237
)

language/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn test_vec_pack() {
7373
max_fields_in_struct: Some(30),
7474
max_function_definitions: Some(1000),
7575
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
76+
..Default::default()
7677
},
7778
&m,
7879
)

language/move-bytecode-verifier/src/verifier.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ pub struct VerifierConfig {
3434
pub max_fields_in_struct: Option<usize>,
3535
pub max_function_definitions: Option<usize>,
3636
pub max_constant_vector_len: u64,
37+
// Max number of nodes which are allowed when instantiating a generic type.
38+
// This does not include field types of structs.
39+
pub max_type_instantiation_size: Option<usize>,
40+
// Max number of nodes which are allowed when instantiating a generic function.
41+
pub max_function_instantiation_size: Option<usize>,
3742
}
3843

3944
/// Helper for a "canonical" verification of a module.
@@ -144,6 +149,8 @@ impl Default for VerifierConfig {
144149
max_function_definitions: None,
145150
// Max len of vector constant
146151
max_constant_vector_len: MAX_CONSTANT_VECTOR_LEN,
152+
max_type_instantiation_size: None,
153+
max_function_instantiation_size: None,
147154
}
148155
}
149156
}

language/move-vm/integration-tests/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ edition = "2021"
1313

1414
[dependencies]
1515
anyhow = "1.0.52"
16+
once_cell = "1.7.2"
1617
tempfile = "3.2.0"
1718
memory-stats = "1.0.0"
1819

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

30+
bcs.workspace = true
31+
2932
[features]
3033
default = []
3134
table-extension = [

language/move-vm/integration-tests/src/tests/limits_tests.rs

Lines changed: 2788 additions & 0 deletions
Large diffs are not rendered by default.

language/move-vm/integration-tests/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod function_arg_tests;
1010
mod instantiation_tests;
1111
mod invariant_violation_tests;
1212
mod leak_tests;
13+
mod limits_tests;
1314
mod loader_tests;
1415
mod mutated_accounts_tests;
1516
mod nested_loop_tests;

language/move-vm/runtime/src/interpreter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ impl Frame {
12931293
interpreter.operand_stack.push_ty(output_ty)?;
12941294
}
12951295
Bytecode::PackGeneric(idx) => {
1296-
let field_count = resolver.field_instantiation_count(*idx);
1296+
let field_count = resolver.field_instantiation_count(*idx, ty_args)?;
12971297
let args_ty = resolver.instantiate_generic_struct_fields(*idx, ty_args)?;
12981298
let output_ty = resolver.instantiate_generic_type(*idx, ty_args)?;
12991299
let ability = resolver.loader().abilities(&output_ty)?;
@@ -1851,7 +1851,8 @@ impl Frame {
18511851
.push(Value::struct_(Struct::pack(args)))?;
18521852
}
18531853
Bytecode::PackGeneric(si_idx) => {
1854-
let field_count = resolver.field_instantiation_count(*si_idx);
1854+
let field_count =
1855+
resolver.field_instantiation_count(*si_idx, self.ty_args())?;
18551856
gas_meter.charge_pack(
18561857
true,
18571858
interpreter.operand_stack.last_n(field_count as usize)?,

0 commit comments

Comments
 (0)