Skip to content

Solidity SDK

As a supplement to OpenVM, we provide a Solidity SDK containing OpenVM verifier contracts generated at official release commits using the cargo openvm setup --evm command. The contracts are built at every minor release as OpenVM guarantees verifier backward compatibility across patch releases.

Note that these builds are for the default aggregation VM config which should be sufficient for most users. If you use a custom config, you will need to manually generate the verifier contract using the OpenVM SDK.

Starting from v2.0, each release provides two verifier variants, in src/v[OPENVM_VERSION]-base and src/v[OPENVM_VERSION]-deferral:

  • base: verifies proofs generated with deferrals disabled (the default). This is the variant generated by cargo openvm setup --evm.
  • deferral: verifies proofs generated with a deferral-aware aggregation config.

The two variants have different verifying keys, so you must use the variant matching your proving setup.

Installation

To install the Solidity SDK as a dependency into your forge project, run the following command:

forge install openvm-org/openvm-solidity-sdk

Usage

Once you have the SDK installed, you can import the SDK contracts into your Solidity project:

import "openvm-solidity-sdk/v2.0-base/OpenVmHalo2Verifier.sol";

If you are proving with deferrals enabled, replace base with deferral in the import paths.

If you are using an already-deployed verifier contract, you can simply import the IOpenVmHalo2Verifier interface:

import { IOpenVmHalo2Verifier } from "openvm-solidity-sdk/v2.0-base/interfaces/IOpenVmHalo2Verifier.sol";
 
contract MyContract {
    function myFunction() public view {
        // ... snip ...
 
        IOpenVmHalo2Verifier(verifierAddress)
            .verify(publicValues, proofData, appExeCommit, appVmCommit);
 
        // ... snip ...
    }
}

The arguments to the verify function are the fields in the EVM Proof JSON Format. Since the builds use the default aggregation VM config, the number of public values is fixed to 32.

If you want to import the verifier contract into your own repository for testing purposes, note that it is locked to Solidity version 0.8.19. If your project uses a different version, the import may not compile. As a workaround, you can compile the contract separately and use vm.etch() to inject the raw bytecode into your tests.

Deployment

To deploy an instance of a verifier contract, you can clone the repo and simply use forge create:

git clone --recursive --branch v2.0-beta https://github.com/openvm-org/openvm-solidity-sdk.git
cd openvm-solidity-sdk
forge create src/v2.0-base/OpenVmHalo2Verifier.sol:OpenVmHalo2Verifier --rpc-url $RPC --private-key $PRIVATE_KEY --broadcast

We recommend a direct deployment from the SDK repo since the proper compiler configurations are all pre-set.