// SPDX-License-Identifier: MIT /* AUTOGENERATED FILE BY HARDHAT-ZKIT. DO NOT EDIT. */ pragma solidity >=0.7.0 <0.9.0; contract <%=verifier_id%> { // @dev scalar field size uint256 public constant SCALAR_FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617; /// @dev base field size uint256 public constant BASE_FIELD_SIZE = 21888242871839275222246405745257275088696311157297823662689037894645226208583; /// @dev verification key data uint256 public constant ALPHA_X = <%=vk_alpha_1[0]%>; uint256 public constant ALPHA_Y = <%=vk_alpha_1[1]%>; uint256 public constant BETA_X1 = <%=vk_beta_2[0][1]%>; uint256 public constant BETA_X2 = <%=vk_beta_2[0][0]%>; uint256 public constant BETA_Y1 = <%=vk_beta_2[1][1]%>; uint256 public constant BETA_Y2 = <%=vk_beta_2[1][0]%>; uint256 public constant GAMMA_X1 = <%=vk_gamma_2[0][1]%>; uint256 public constant GAMMA_X2 = <%=vk_gamma_2[0][0]%>; uint256 public constant GAMMA_Y1 = <%=vk_gamma_2[1][1]%>; uint256 public constant GAMMA_Y2 = <%=vk_gamma_2[1][0]%>; uint256 public constant DELTA_X1 = <%=vk_delta_2[0][1]%>; uint256 public constant DELTA_X2 = <%=vk_delta_2[0][0]%>; uint256 public constant DELTA_Y1 = <%=vk_delta_2[1][1]%>; uint256 public constant DELTA_Y2 = <%=vk_delta_2[1][0] -%>; <% for (let i = 0; i < IC.length; i++) { %>uint256 public constant IC<%=i%>_X = <%=IC[i][0]%>; uint256 public constant IC<%=i%>_Y = <%=IC[i][1]%>; <% } -%> /// @dev memory pointer size uint256 public constant P_TOTAL_SIZE = 768; function verifyProof( uint256[2] memory pointA_, uint256[2][2] memory pointB_, uint256[2] memory pointC_, uint256[<%=IC.length - 1%>] memory publicSignals_ ) public view returns (bool verified_) { assembly { function checkField(signal_) -> res_ { res_ := lt(signal_, SCALAR_FIELD_SIZE) } function g1MulAdd(pointer_, x_, y_, s_) -> res_ { mstore(add(pointer_, 64), x_) mstore(add(pointer_, 96), y_) mstore(add(pointer_, 128), s_) res_ := staticcall(6000, 7, add(pointer_, 64), 96, add(pointer_, 64), 64) // ecMul res_ := and(res_, gt(returndatasize(), 0)) // check that multiplication succeeded if iszero(res_) { leave } res_ := staticcall(150, 6, pointer_, 128, pointer_, 64) // ecAdd res_ := and(res_, gt(returndatasize(), 0)) // check that addition succeeded } function checkPairing(pA_, pB_, pC_, pubSignals_, pointer_) -> res_ { mstore(pointer_, IC0_X) mstore(add(pointer_, 32), IC0_Y) /// @dev compute the linear combination of public signals <% for (let i = 1; i <= nPublic; i++) { %>if iszero(g1MulAdd(pointer_, IC<%=i%>_X, IC<%=i%>_Y, mload(add(pubSignals_, <%=(i - 1) * 32%>)))) { leave } <% } -%> /// @dev gamma2 mstore(add(pointer_, 64), GAMMA_X1) mstore(add(pointer_, 96), GAMMA_X2) mstore(add(pointer_, 128), GAMMA_Y1) mstore(add(pointer_, 160), GAMMA_Y2) /// @dev -A mstore(add(pointer_, 192), mload(pA_)) mstore( add(pointer_, 224), mod(sub(BASE_FIELD_SIZE, mload(add(pA_, 32))), BASE_FIELD_SIZE) ) /// @dev B mstore(add(pointer_, 256), mload(mload(pB_))) mstore(add(pointer_, 288), mload(add(mload(pB_), 32))) mstore(add(pointer_, 320), mload(mload(add(pB_, 32)))) mstore(add(pointer_, 352), mload(add(mload(add(pB_, 32)), 32))) /// @dev alpha1 mstore(add(pointer_, 384), ALPHA_X) mstore(add(pointer_, 416), ALPHA_Y) /// @dev beta2 mstore(add(pointer_, 448), BETA_X1) mstore(add(pointer_, 480), BETA_X2) mstore(add(pointer_, 512), BETA_Y1) mstore(add(pointer_, 544), BETA_Y2) /// @dev C mstore(add(pointer_, 576), mload(pC_)) mstore(add(pointer_, 608), mload(add(pC_, 32))) /// @dev delta2 mstore(add(pointer_, 640), DELTA_X1) mstore(add(pointer_, 672), DELTA_X2) mstore(add(pointer_, 704), DELTA_Y1) mstore(add(pointer_, 736), DELTA_Y2) res_ := staticcall(181000, 8, pointer_, 768, pointer_, 32) // ecPairing res_ := and(res_, mload(pointer_)) // check that pairing succeeded } let pointer_ := mload(64) // free pointer mstore(64, add(pointer_, P_TOTAL_SIZE)) /// @dev check that all public signals are in F verified_ := 1 <% for (let i = 0; i < nPublic; i++) { %>verified_ := and(verified_, checkField(mload(add(publicSignals_, <%=i * 32%>)))) <% } -%> /// @dev check pairings if not(iszero(verified_)) { verified_ := checkPairing(pointA_, pointB_, pointC_, publicSignals_, pointer_) } } } }