-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[language][Bytecode Verifier] Fix Stack Usage Verifier
This commit fixes the way instructions effects on the stack height are computed so that the subtractions from the stack height are checked separately from the additions. Closes: diem#1003 Approved by: shazqadeer
- Loading branch information
1 parent
58c557f
commit e04c869
Showing
3 changed files
with
130 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...age/bytecode_verifier/bytecode_verifier_tests/src/unit_tests/negative_stack_size_tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use bytecode_verifier::CodeUnitVerifier; | ||
use types::vm_error::StatusCode; | ||
use vm::file_format::{self, Bytecode}; | ||
|
||
#[test] | ||
fn one_pop_no_push() { | ||
let module = file_format::dummy_procedure_module(vec![Bytecode::Pop, Bytecode::Ret]); | ||
let errors = CodeUnitVerifier::verify(&module); | ||
println!("{:?}", errors); | ||
assert_eq!( | ||
errors[0].major_status, | ||
StatusCode::NEGATIVE_STACK_SIZE_WITHIN_BLOCK | ||
); | ||
} | ||
|
||
#[test] | ||
fn one_pop_one_push() { | ||
// Height: 0 + (-1 + 1) = 0 would have passed original usage verifier | ||
let module = file_format::dummy_procedure_module(vec![Bytecode::ReadRef, Bytecode::Ret]); | ||
let errors = CodeUnitVerifier::verify(&module); | ||
assert_eq!( | ||
errors[0].major_status, | ||
StatusCode::NEGATIVE_STACK_SIZE_WITHIN_BLOCK | ||
); | ||
} | ||
|
||
#[test] | ||
fn two_pop_one_push() { | ||
// Height: 0 + 1 + (-2 + 1) = 0 would have passed original usage verifier | ||
let module = file_format::dummy_procedure_module(vec![ | ||
Bytecode::LdConst(0), | ||
Bytecode::Add, | ||
Bytecode::Ret, | ||
]); | ||
let errors = CodeUnitVerifier::verify(&module); | ||
assert_eq!( | ||
errors[0].major_status, | ||
StatusCode::NEGATIVE_STACK_SIZE_WITHIN_BLOCK | ||
); | ||
} | ||
|
||
#[test] | ||
fn two_pop_no_push() { | ||
let module = file_format::dummy_procedure_module(vec![Bytecode::WriteRef, Bytecode::Ret]); | ||
let errors = CodeUnitVerifier::verify(&module); | ||
assert_eq!( | ||
errors[0].major_status, | ||
StatusCode::NEGATIVE_STACK_SIZE_WITHIN_BLOCK | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters