Skip to main content

Halmos: Symbolic Bounded Model Checker for Ethereum Smart Contracts Bytecode

Project description

Halmos

License chat

Symbolic Bounded Model Checker for Ethereum Smart Contracts Bytecode

Symbolic: Halmos executes the given contract bytecode with symbolic function arguments and symbolic storage states, enabling it to systematically explore all possible behaviors of the contract.

Bounded: Halmos unrolls loops up to a specified bound and sets the size of variable-length arrays, allowing it to run automatically without the need for additional user annotations.

Model Checking: Halmos proves that assertions are never violated by any inputs or provides a counter-example. This allows Halmos to be used for bug detection as well as formal verification of the contract.

For more information, refer to our post on "Symbolic testing with Halmos: Leveraging existing tests for formal verification."

Join the Halmos Telegram Group for any inquiries or further discussions.

Installation

$ pip install halmos

Usage

$ cd /path/to/src
$ halmos

For more details:

$ halmos --help

Examples

Given a contract, Example.sol:

contract Example {
    function totalPriceBuggy(uint96 price, uint32 quantity) public pure returns (uint128) {
        unchecked {
            return uint120(price) * quantity; // buggy type casting: uint120 vs uint128
        }
    }
}

You write some property-based tests (in Solidity), Example.t.sol:

contract ExampleTest is Example {
    function testTotalPriceBuggy(uint96 price, uint32 quantity) public pure {
        uint128 total = totalPriceBuggy(price, quantity);
        assert(quantity == 0 || total >= price);
    }
}

Then you can run fuzz testing to quickly check those properties for some random inputs:

$ forge test
[PASS] testTotalPriceBuggy(uint96,uint32) (runs: 256, μ: 462, ~: 466)

Once it passes, you can also perform symbolic testing to verify the same properties for all possible inputs (up to a specified limit):

$ halmos
[FAIL] testTotalPriceBuggy(uint96,uint32) (paths: 6, time: 0.10s, bounds: [])
Counterexample: [p_price_uint96 = 39614081294025656978550816768, p_quantity_uint32 = 1073741824]

(In this specific example, Halmos discovered an input that violated the assertion, which was missed by the fuzzer!)

Disclaimer

These smart contracts and code are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts and code. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. THE SMART CONTRACTS AND CODE CONTAINED HEREIN ARE FURNISHED AS IS, WHERE IS, WITH ALL FAULTS AND WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, NON-INFRINGEMENT OR FITNESS FOR ANY PARTICULAR PURPOSE. Further, use of any of these smart contracts and code may be restricted or prohibited under applicable law, including securities laws, and it is therefore strongly advised for you to contact a reputable attorney in any jurisdiction where these smart contracts and code may be accessible for any questions or concerns with respect thereto. Further, no information provided in this repo should be construed as investment advice or legal advice for any particular facts or circumstances, and is not meant to replace competent counsel. a16z is not liable for any use of the foregoing, and users should proceed with caution and use at their own risk. See a16z.com/disclosures for more info.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

halmos-0.0.7.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

halmos-0.0.7-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

Details for the file halmos-0.0.7.tar.gz.

File metadata

  • Download URL: halmos-0.0.7.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for halmos-0.0.7.tar.gz
Algorithm Hash digest
SHA256 585a0871d44d42d07b4132867e2c5fcdbf219b9e91512d9e940b23f9a6755c32
MD5 f4387f269316f68b8f0a36d2cb00ce40
BLAKE2b-256 103c004ad0094baa80d2e41e043f3b7ac8a5b82c00e54fa717d6a7a5b6db2483

See more details on using hashes here.

File details

Details for the file halmos-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: halmos-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for halmos-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e1689706a765ee1b16693bee3c250d4173b589fffd097a393d64805f78b69609
MD5 a68495becfbab50e41e8f4b9f25e6248
BLAKE2b-256 0f6467f484e2f719a0c16dfbf0b2ffdb8f8a278a4acc46e90f91ea52cdae9dff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page