Skip to content

Branch Explosion in halmos (Yices SMT Solver) Due to PR #693 #705

@pcaversaccio

Description

@pcaversaccio

Summary

In 🐍 snekmate, I run symbolic execution nightly tests in the CI based on halmos (latest master version) using the Yices SMT solver version 2.6.4:

3 days ago the nightly tests started failing since they were running out of time (i.e. beyond the standard 3hrs GitHub threshold):

After careful (and time-consuming lol) investigation, I was able to find the issue. I updated 4 days ago to the latest forge-std master commit c7be2a3. After running and testing the CI for hours, the following commit introduces the "regression": 276ccaa.

So what's the underlying problem? Specifically, my ERC1155TestHalmos test contract and its test testHalmosAssertNoBackdoor is running out of time. You can see the usage of assertLe and assertGe here:

for (uint256 i = 0; i < tokenIds.length; i++) {
    assertLe(erc1155.balanceOf(caller, tokenIds[i]), oldBalanceCaller[i]);
    assertGe(erc1155.balanceOf(other, tokenIds[i]), oldBalanceOther[i]);
}

But also the test testHalmosSafeTransferFrom struggles since I use assertEq here:

if (from != to) {
    assertEq(newBalanceFrom, oldBalanceFrom - amounts[0]);
    assertEq(newBalanceTo, oldBalanceTo + amounts[0]);
} else {
    assertEq(newBalanceFrom, oldBalanceFrom);
    assertEq(newBalanceTo, oldBalanceTo);
}

assertEq(newBalanceOther, oldBalanceOther);

The commit 276ccaa (and the refactor later 349b909) introduce additional branching conditions which produce a path explosion. I'm not a formal verification expert, so I can't explain exactly why, but you can see the tests here:

There are 2 ways forward for me in the current status quo:

  1. Pin an older forge-std version -> not sustainable
  2. Directly use vm.assertGe and vm.assertLe -> ugly solution

I'm not sure if you are open to reconsider this change, but it's important to understand that such small optimisation changes can have breaking impacts downstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions