Skip to main content

Deploying the Wrapper Contract

IVerifier Interface

Wrapper contracts standardize the interface for various zkApps, ensuring seamless integration with Kalypso. They act as an adaptor layer, eliminating the need for zkApp developers to directly modify their verifier code. A wrapper contract is expected to extend the abstract contract IVerifier

// SPDX-License-Identifier: MIT

import "../ProofMarketplace.sol";

pragma solidity ^0.8.0;

abstract contract IVerifier {
function verify(bytes calldata encodedPublicInputsAndProofs) external view virtual returns (bool);

function verifyInputs(bytes calldata inputs) external view virtual returns (bool);

function sampleInput() external view virtual returns (bytes memory);

function sampleProof() external view virtual returns (bytes memory);

function verifyAgainstSampleInputs(bytes memory proof) external view virtual returns (bool);

function checkSampleInputsAndProof() external view virtual returns (bool);
}

The Wrapper contract is expected to implement IVerifier and address of Wrapper is contract is to be used at Kalypso's market place. As an example.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../interfaces/IVerifier.sol";

interface i_transfer_verifier {
function verifyProof(uint256[5] memory input, uint256[8] memory p) external view returns (bool);
}

contract transfer_verifier_wrapper is IVerifier {
i_transfer_verifier public immutable iverifier;

bytes public override sampleInput;
bytes public override sampleProof;

constructor(i_transfer_verifier _iverifier, bytes memory _sampleInput, bytes memory _sampleProof) {
iverifier = _iverifier;

sampleInput = _sampleInput;
sampleProof = _sampleProof;

require(checkSampleInputsAndProof(), "Can't be deployed");
}


// ........

function verify(bytes memory encodedData) public view override returns (bool) {
uint256[5] memory input;
uint256[8] memory p;

(bytes memory encodedInputs, bytes memory encodedProofs) = abi.decode(encodedData, (bytes, bytes));

(input) = abi.decode(encodedInputs, (uint256[5]));
(p) = abi.decode(encodedProofs, (uint256[8]));

return iverifier.verifyProof(input, p);
}

// ........
}

A complete implementation of simple wrapper contract can be found here.