Skip to content

Commit 98346d8

Browse files
committed
chore: address comments
1 parent 5d3cd40 commit 98346d8

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

src/Halo2Verifier.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.19;
33

4-
contract AxiomV2QueryVerifier {
4+
contract Halo2Verifier {
55
fallback(bytes calldata) external returns (bytes memory) {
66
// assembly ("memory-safe") {
77
// // Enforce that Solidity memory layout is respected

src/OpenVmHalo2Verifier.sol

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity 0.8.19;
33

4-
import { AxiomV2QueryVerifier } from "./Halo2Verifier.sol";
4+
import { Halo2Verifier } from "./Halo2Verifier.sol";
55

66
type MemoryPointer is uint256;
77

88
/// @notice This contract provides a thin wrapper around the Halo2 verifier
99
/// outputted by `snark-verifier`, exposing a more user-friendly interface.
10-
contract OpenVmHalo2Verifier is AxiomV2QueryVerifier {
10+
contract OpenVmHalo2Verifier is Halo2Verifier {
1111
/// @dev Invalid partial proof length
1212
error InvalidPartialProofLength();
1313

@@ -26,6 +26,12 @@ contract OpenVmHalo2Verifier is AxiomV2QueryVerifier {
2626
/// @dev The length of the full proof, in bytes
2727
uint256 private constant FULL_PROOF_LENGTH = (12 + 2 + GUEST_PVS_LENGTH + 43) * 32;
2828

29+
/// @dev The leaf verifier commitment. This value is set by OpenVM.
30+
bytes32 public constant LEAF_EXE_COMMIT =
31+
bytes32(0x0000000000000000000000000000000000000000000000000000000000000000);
32+
33+
string public constant OPENVM_VERSION = "v1.0.0";
34+
2935
/// @notice A wrapper that constructs the proof into the right format for
3036
/// use with the `snark-verifier` verification.
3137
///
@@ -53,19 +59,18 @@ contract OpenVmHalo2Verifier is AxiomV2QueryVerifier {
5359
/// @param guestPvs The PVs revealed by the OpenVM guest program.
5460
/// @param appExeCommit The commitment to the RISC-V executable whose execution
5561
/// is being verified.
56-
/// @param leafExeCommit The commitment to the leaf verifier.
57-
function verifyProof(
58-
bytes calldata guestPvs,
59-
bytes calldata partialProof,
60-
bytes32 appExeCommit,
61-
bytes32 leafExeCommit
62-
) external view {
62+
function verify(bytes calldata guestPvs, bytes calldata partialProof, bytes32 appExeCommit) external view {
63+
if (guestPvs.length != GUEST_PVS_LENGTH) revert InvalidGuestPvsLength();
64+
if (partialProof.length != PARTIAL_PROOF_LENGTH) revert InvalidPartialProofLength();
65+
6366
// We will format the public values and construct the full proof payload
6467
// below.
6568

66-
MemoryPointer proofPtr = _constructProof(guestPvs, partialProof, appExeCommit, leafExeCommit);
69+
MemoryPointer proofPtr = _constructProof(guestPvs, partialProof, appExeCommit);
6770

6871
uint256 fullProofLength = FULL_PROOF_LENGTH;
72+
73+
/// @solidity memory-safe-assembly
6974
assembly {
7075
// Self-call using the proof as calldata
7176
if iszero(staticcall(gas(), address(), proofPtr, fullProofLength, 0, 0)) {
@@ -75,15 +80,11 @@ contract OpenVmHalo2Verifier is AxiomV2QueryVerifier {
7580
}
7681
}
7782

78-
function _constructProof(
79-
bytes calldata guestPvs,
80-
bytes calldata partialProof,
81-
bytes32 appExeCommit,
82-
bytes32 leafExeCommit
83-
) internal pure returns (MemoryPointer proofPtr) {
84-
if (guestPvs.length != GUEST_PVS_LENGTH) revert InvalidGuestPvsLength();
85-
if (partialProof.length != PARTIAL_PROOF_LENGTH) revert InvalidPartialProofLength();
86-
83+
function _constructProof(bytes calldata guestPvs, bytes calldata partialProof, bytes32 appExeCommit)
84+
internal
85+
pure
86+
returns (MemoryPointer proofPtr)
87+
{
8788
// The assembly code should perform the same function as the following
8889
// solidity code:
8990
//
@@ -96,6 +97,7 @@ contract OpenVmHalo2Verifier is AxiomV2QueryVerifier {
9697
// `guestPvs` separated into its own word.
9798

9899
uint256 fullProofLength = FULL_PROOF_LENGTH;
100+
bytes32 leafExeCommit = LEAF_EXE_COMMIT;
99101

100102
/// @solidity memory-safe-assembly
101103
assembly {

test/OpenVmHalo2Verifier.t.sol

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { Test, console2, safeconsole as console } from "forge-std/Test.sol";
77
contract OpenVmHalo2VerifierTest is Test, OpenVmHalo2Verifier {
88
bytes partialProof;
99
bytes32 appExeCommit = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
10-
bytes32 leafExeCommit = 0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE;
11-
bytes32 guestPvsHash = 0xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;
10+
bytes32 guestPvsHash = 0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE;
1211

1312
uint256 private constant FULL_PROOF_WORDS = (12 + 2 + 32 + 43);
1413

@@ -24,22 +23,16 @@ contract OpenVmHalo2VerifierTest is Test, OpenVmHalo2Verifier {
2423
}
2524

2625
function test_verifyProof() public view {
27-
this.verifyProof(abi.encodePacked(guestPvsHash), partialProof, appExeCommit, leafExeCommit);
26+
this.verify(abi.encodePacked(guestPvsHash), partialProof, appExeCommit);
2827
}
2928

3029
function test_proofFormat() public view {
31-
this.constructAndCheckProof(abi.encodePacked(guestPvsHash), partialProof, appExeCommit, leafExeCommit);
30+
this.constructAndCheckProof(abi.encodePacked(guestPvsHash), partialProof, appExeCommit);
3231
}
3332

34-
function testFuzz_proofFormat(
35-
uint256 partialProofSeed,
36-
bytes32 _guestPvsHash,
37-
bytes32 _appExeCommit,
38-
bytes32 _leafExeCommit
39-
) public {
33+
function testFuzz_proofFormat(uint256 partialProofSeed, bytes32 _guestPvsHash, bytes32 _appExeCommit) public {
4034
vm.assume(_guestPvsHash != bytes32(0));
4135
vm.assume(_appExeCommit != bytes32(0));
42-
vm.assume(_leafExeCommit != bytes32(0));
4336

4437
bytes memory _partialProof = new bytes(55 * 32);
4538
for (uint256 i = 0; i < 55 * 32; ++i) {
@@ -50,18 +43,15 @@ contract OpenVmHalo2VerifierTest is Test, OpenVmHalo2Verifier {
5043
partialProof = _partialProof;
5144
guestPvsHash = _guestPvsHash;
5245
appExeCommit = _appExeCommit;
53-
leafExeCommit = _leafExeCommit;
5446

5547
test_proofFormat();
5648
}
5749

58-
function constructAndCheckProof(
59-
bytes calldata _guestPvs,
60-
bytes calldata _partialProof,
61-
bytes32 _appExeCommit,
62-
bytes32 _leafExeCommit
63-
) external view {
64-
MemoryPointer proofPtr = _constructProof(_guestPvs, _partialProof, _appExeCommit, _leafExeCommit);
50+
function constructAndCheckProof(bytes calldata _guestPvs, bytes calldata _partialProof, bytes32 _appExeCommit)
51+
external
52+
view
53+
{
54+
MemoryPointer proofPtr = _constructProof(_guestPvs, _partialProof, _appExeCommit);
6555

6656
// _constructProof will return a pointer to memory that will hold the
6757
// proof data in a block of size FULL_PROOF_LENGTH. However, this won't
@@ -112,7 +102,7 @@ contract OpenVmHalo2VerifierTest is Test, OpenVmHalo2Verifier {
112102
bytes memory _leafExeCommit = proof[0x1a0:0x1c0];
113103

114104
require(bytes32(_appExeCommit) == appExeCommit, "App exe commit mismatch");
115-
require(bytes32(_leafExeCommit) == leafExeCommit, "Leaf exe commit mismatch");
105+
require(bytes32(_leafExeCommit) == LEAF_EXE_COMMIT, "Leaf exe commit mismatch");
116106

117107
bytes32 guestPvsHashExpected = guestPvsHash;
118108
bytes calldata _guestPvsHash = proof[0x1c0:0x5c0];
@@ -125,11 +115,11 @@ contract OpenVmHalo2VerifierTest is Test, OpenVmHalo2Verifier {
125115

126116
function test_RevertWhen_InvalidPartialProofLength() public {
127117
vm.expectRevert(abi.encodeWithSelector(OpenVmHalo2Verifier.InvalidPartialProofLength.selector));
128-
this.verifyProof(abi.encodePacked(guestPvsHash), hex"aa", appExeCommit, leafExeCommit);
118+
this.verify(abi.encodePacked(guestPvsHash), hex"aa", appExeCommit);
129119
}
130120

131121
function test_RevertWhen_InvalidGuestPvsLength() public {
132122
vm.expectRevert(abi.encodeWithSelector(OpenVmHalo2Verifier.InvalidGuestPvsLength.selector));
133-
this.verifyProof(partialProof, hex"aa", appExeCommit, leafExeCommit);
123+
this.verify(partialProof, hex"aa", appExeCommit);
134124
}
135125
}

0 commit comments

Comments
 (0)