diff --git a/src/Verifier.sol b/src/Verifier.sol index db37aab..c9e59ad 100644 --- a/src/Verifier.sol +++ b/src/Verifier.sol @@ -5,8 +5,10 @@ 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"; @@ -14,6 +16,7 @@ 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 @@ -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; + } } diff --git a/src/libraries/darkpool/Types.sol b/src/libraries/darkpool/Types.sol index d1b06c4..4846b36 100644 --- a/src/libraries/darkpool/Types.sol +++ b/src/libraries/darkpool/Types.sol @@ -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)"); @@ -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 diff --git a/src/libraries/verifier/IVerifier.sol b/src/libraries/verifier/IVerifier.sol index a82e9a3..56d11db 100644 --- a/src/libraries/verifier/IVerifier.sol +++ b/src/libraries/verifier/IVerifier.sol @@ -2,7 +2,12 @@ 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` @@ -10,8 +15,8 @@ interface IVerifier { /// @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 @@ -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 diff --git a/test/test-contracts/TestVerifier.sol b/test/test-contracts/TestVerifier.sol index 1c4a732..93dcf12 100644 --- a/test/test-contracts/TestVerifier.sol +++ b/test/test-contracts/TestVerifier.sol @@ -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"; @@ -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; } @@ -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; } }