[prover] monomorphization never builds the all-equal type case
Bug
The prover checks a generic function on a set of type cases. It builds those cases by pairing type parameters two at a time. It never joins the pairs. So it never builds the case where all three type parameters are the same. A function that is only wrong in that case still passes.
write_and_check writes false to R<T>, false to R<U> and true to
R<V>. Then it returns whether R<T> or R<U> is still false. One false
is always left when V is not T and not U. When T, U and V are all
the same type, the three writes hit one resource. The last write sets it to
true. Then the function returns false. The prover accepts
ensures result == true.
To reproduce
- Save the snippet as
third_party/move/move-prover/tests/sources/regression/unsoundness_showcase/06_missing_all_equal_root.move. - Create an empty
.expfile next to it with the same base name. - Run
cargo test -p move-prover --test testsuite 06_missing_all_equal_root -- --test-threads=1.
The test passes. The prover checks the open generic case and the six pair cases. It never makes the case where all three type parameters are the same.
Code snippet to reproduce
module 0x42::missing_all_equal_root {
struct R<phantom T> has key {
value: bool,
}
public fun write_and_check<T, U, V>(a: address): bool {
R<T>[a].value = false;
R<U>[a].value = false;
R<V>[a].value = true;
R<T>[a].value == false
|| R<U>[a].value == false
}
spec write_and_check {
requires exists<R<T>>(a)
&& exists<R<U>>(a)
&& exists<R<V>>(a);
ensures result == true;
}
#[test(user = @0x42)]
fun write_and_check_test(user: &signer) {
move_to(user, R<u8> { value: false });
assert_eq!(write_and_check<u8, u8, u8>(user.address_of()), false);
}
}Expected Behavior
The prover should build the case T = U = V and reject the postcondition:
error: post-condition does not hold
06_missing_all_equal_root.move
ensures result == true;Set T, U and V all to u8. Pick an address a that holds R<u8>. Now
all three writes hit the same R<u8>. The last write leaves it true. Both
checks read true == false. So the function returns false || false. That
breaks result == true. The Move unit test in the snippet shows the same
result.
Additional context
The pair cases are built and merged, but never combined with each other. See
third_party/move/move-prover/bytecode-pipeline/src/mono_analysis.rs:1485-1531.
That gives the pairs and never T = U = V.
The backend only writes out the cases kept in MonoInfo. See
third_party/move/move-prover/boogie-backend/src/bytecode_translator.rs:340-396.
So the all equal case never reaches Boogie.
Source: aptos-labs/aptos-core