Skip to content

Commit

Permalink
fix: improve dynexec/procref test
Browse files Browse the repository at this point in the history
The previous version of this test started to fail because it assumed
that it could blindly call u64::wrapping_add on a word representing the
hash of a procedure. This is not actually safe, as there is no guarantee
the hash will consist of 4 valid 32-bit limbs - and in fact that is what
caused it to start to fail here - the procedure hash changed, was no
longer valid for use as an operand to that function, and caused
execution to trap deep in the VM.

This commit changes the test to use actual checked operands, and adds a
separate module into the mix to facilitate testing that procref/dynexec
works across modules.
  • Loading branch information
bitwalker committed Mar 9, 2024
1 parent ddfb84d commit dda2489
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions miden/tests/integration/flow_control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ fn simple_dyn_exec() {
#[test]
fn dynexec_with_procref() {
let program_source = "
use.std::math::u64
use.external::module
proc.foo
dropw
push.1.2
u32wrapping_add
end
Expand All @@ -292,22 +293,27 @@ fn dynexec_with_procref() {
procref.foo
dynexec
procref.u64::wrapping_add
procref.module::func
dynexec
dup
push.4
assert_eq.err=101
end";

let mut test = build_test!(program_source, &[]);
test.libraries = vec![StdLibrary::default().into()];
test.add_module(
"external::module".parse().unwrap(),
"\
export.func
dropw
u32wrapping_add.1
end
",
);

test.expect_stack(&[
1719755471,
1057995821,
3,
12973202366681443424,
7933716460165146367,
14382661273226268231,
15818904913409383971,
]);
test.expect_stack(&[4]);
}

#[test]
Expand Down

0 comments on commit dda2489

Please sign in to comment.