Skip to content

Commit

Permalink
libraries: verifier: IVerifier: Add settlement verification interface
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Mar 6, 2025
1 parent 2dae947 commit d12e85f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { PlonkProof, VerificationKey } from "./libraries/verifier/Types.sol";
import {
ValidWalletCreateStatement,
ValidWalletUpdateStatement,
ValidMatchSettleStatement,
StatementSerializer
} from "./libraries/darkpool/PublicInputs.sol";
import { PartyMatchPayload, MatchProofs } from "./libraries/darkpool/Types.sol";
import { VerificationKeys } from "./libraries/darkpool/VerificationKeys.sol";
import { IVerifier } from "./libraries/verifier/IVerifier.sol";
import { VerifierCore } from "./libraries/verifier/VerifierCore.sol";
import { BN254 } from "solidity-bn254/BN254.sol";

using StatementSerializer for ValidWalletCreateStatement;
using StatementSerializer for ValidWalletUpdateStatement;
using StatementSerializer for ValidMatchSettleStatement;

/// @title PlonK Verifier with the Jellyfish-style arithmetization
/// @notice The methods on this contract are darkpool-specific
Expand Down Expand Up @@ -51,4 +54,23 @@ contract Verifier is IVerifier {
BN254.ScalarField[] memory publicInputs = statement.scalarSerialize();
return VerifierCore.verify(proof, publicInputs, vk);
}

/// @notice Verify a match bundle
/// @param party0MatchPayload The payload for the first party
/// @param party1MatchPayload The payload for the second party
/// @param matchSettleStatement The statement of `VALID MATCH SETTLE`
/// @param proofs The proofs for the match, including two sets of validity proofs and a settlement proof
/// @return True if the match bundle is valid, false otherwise
function verifyMatchBundle(
PartyMatchPayload calldata party0MatchPayload,
PartyMatchPayload calldata party1MatchPayload,
ValidMatchSettleStatement calldata matchSettleStatement,
MatchProofs calldata proofs
)
external
view
returns (bool)
{
return false;
}
}
26 changes: 26 additions & 0 deletions src/libraries/darkpool/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.0;
// This file contains the types used in the darkpool

import { BN254 } from "solidity-bn254/BN254.sol";
import { ValidCommitmentsStatement, ValidReblindStatement } from "./PublicInputs.sol";
import { PlonkProof } from "../verifier/Types.sol";

/// @dev The type hash for the DepositWitness struct
bytes32 constant DEPOSIT_WITNESS_TYPEHASH = keccak256("DepositWitness(uint256[4] pkRoot)");
Expand Down Expand Up @@ -82,6 +84,30 @@ function hashDepositWitness(DepositWitness memory witness) pure returns (bytes32
// | Settlement Types |
// --------------------

/// @title PartyMatchPayload
/// @notice Contains the statement types for a single party's validity proofs in a match
struct PartyMatchPayload {
/// @dev The statement types for the `VALID COMMITMENTS` proof
ValidCommitmentsStatement validCommitmentsStatement;
/// @dev The statement types for the `VALID REBLIND` proof
ValidReblindStatement validReblindStatement;
}

/// @title MatchProofs
/// @notice Contains the proofs for a match between two parties in the darkpool
struct MatchProofs {
/// @dev The first party's proof of `VALID COMMITMENTS`
PlonkProof validCommitments0;
/// @dev The first party's proof of `VALID REBLIND`
PlonkProof validReblind0;
/// @dev The second party's proof of `VALID COMMITMENTS`
PlonkProof validCommitments1;
/// @dev The second party's proof of `VALID REBLIND`
PlonkProof validReblind1;
/// @dev The proof of `VALID MATCH SETTLE`
PlonkProof validMatchSettle;
}

/// @notice A set of indices into a settlement party's wallet for the receive balance
struct OrderSettlementIndices {
/// @dev The index of the balance holding the mint which teh wallet will
Expand Down
31 changes: 26 additions & 5 deletions src/libraries/verifier/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
pragma solidity ^0.8.0;

import { PlonkProof } from "./Types.sol";
import { ValidWalletCreateStatement, ValidWalletUpdateStatement } from "../darkpool/PublicInputs.sol";
import {
ValidWalletCreateStatement,
ValidWalletUpdateStatement,
ValidMatchSettleStatement
} from "../darkpool/PublicInputs.sol";
import { PartyMatchPayload, MatchProofs } from "../darkpool/Types.sol";

interface IVerifier {
/// @notice Verify a proof of `VALID WALLET CREATE`
/// @param proof The proof to verify
/// @param statement The public inputs to the proof
/// @return True if the proof is valid, false otherwise
function verifyValidWalletCreate(
ValidWalletCreateStatement memory statement,
PlonkProof memory proof
ValidWalletCreateStatement calldata statement,
PlonkProof calldata proof
)
external
view
Expand All @@ -22,8 +27,24 @@ interface IVerifier {
/// @param statement The public inputs to the proof
/// @return True if the proof is valid, false otherwise
function verifyValidWalletUpdate(
ValidWalletUpdateStatement memory statement,
PlonkProof memory proof
ValidWalletUpdateStatement calldata statement,
PlonkProof calldata proof
)
external
view
returns (bool);

/// @notice Verify a match bundle
/// @param party0MatchPayload The payload for the first party
/// @param party1MatchPayload The payload for the second party
/// @param matchSettleStatement The statement of `VALID MATCH SETTLE`
/// @param proofs The proofs for the match, including two sets of validity proofs and a settlement proof
/// @return True if the match bundle is valid, false otherwise
function verifyMatchBundle(
PartyMatchPayload calldata party0MatchPayload,
PartyMatchPayload calldata party1MatchPayload,
ValidMatchSettleStatement calldata matchSettleStatement,
MatchProofs calldata proofs
)
external
view
Expand Down
45 changes: 35 additions & 10 deletions test/test-contracts/TestVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { PlonkProof, VerificationKey } from "../../src/libraries/verifier/Types.
import {
ValidWalletCreateStatement,
ValidWalletUpdateStatement,
ValidMatchSettleStatement,
StatementSerializer
} from "../../src/libraries/darkpool/PublicInputs.sol";
import { PartyMatchPayload, MatchProofs } from "../../src/libraries/darkpool/Types.sol";
import { VerificationKeys } from "../../src/libraries/darkpool/VerificationKeys.sol";
import { IVerifier } from "../../src/libraries/verifier/IVerifier.sol";
import { Verifier } from "../../src/Verifier.sol";
import { VerifierCore } from "../../src/libraries/verifier/VerifierCore.sol";
import { BN254 } from "solidity-bn254/BN254.sol";

Expand All @@ -19,21 +22,25 @@ using StatementSerializer for ValidWalletUpdateStatement;
/// @notice This is a test implementation of the `IVerifier` interface that always returns true
/// @notice even if verification fails
contract TestVerifier is IVerifier {
Verifier private verifier;

constructor() {
verifier = new Verifier();
}

/// @notice Verify a proof of `VALID WALLET CREATE`
/// @param statement The public inputs to the proof
/// @param proof The proof to verify
/// @return True always, regardless of the proof
function verifyValidWalletCreate(
ValidWalletCreateStatement memory statement,
PlonkProof memory proof
ValidWalletCreateStatement calldata statement,
PlonkProof calldata proof
)
external
view
returns (bool)
{
VerificationKey memory vk = abi.decode(VerificationKeys.VALID_WALLET_CREATE_VKEY, (VerificationKey));
BN254.ScalarField[] memory publicInputs = statement.scalarSerialize();
VerifierCore.verify(proof, publicInputs, vk);
bool _res = verifier.verifyValidWalletCreate(statement, proof);
return true;
}

Expand All @@ -42,16 +49,34 @@ contract TestVerifier is IVerifier {
/// @param proof The proof to verify
/// @return True if the proof is valid, false otherwise
function verifyValidWalletUpdate(
ValidWalletUpdateStatement memory statement,
PlonkProof memory proof
ValidWalletUpdateStatement calldata statement,
PlonkProof calldata proof
)
external
view
returns (bool)
{
bool _res = verifier.verifyValidWalletUpdate(statement, proof);
return true;
}

/// @notice Verify a match bundle
/// @param party0MatchPayload The payload for the first party
/// @param party1MatchPayload The payload for the second party
/// @param matchSettleStatement The statement of `VALID MATCH SETTLE`
/// @param proofs The proofs for the match, including two sets of validity proofs and a settlement proof
/// @return True always, regardless of the proof
function verifyMatchBundle(
PartyMatchPayload calldata party0MatchPayload,
PartyMatchPayload calldata party1MatchPayload,
ValidMatchSettleStatement calldata matchSettleStatement,
MatchProofs calldata proofs
)
external
view
returns (bool)
{
VerificationKey memory vk = abi.decode(VerificationKeys.VALID_WALLET_UPDATE_VKEY, (VerificationKey));
BN254.ScalarField[] memory publicInputs = statement.scalarSerialize();
VerifierCore.verify(proof, publicInputs, vk);
bool _res = verifier.verifyMatchBundle(party0MatchPayload, party1MatchPayload, matchSettleStatement, proofs);
return true;
}
}

0 comments on commit d12e85f

Please sign in to comment.