-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ValidatorTestWrapper and fix test
- Loading branch information
Andriian Chestnykh
committed
Dec 13, 2023
1 parent
0c33bc0
commit cbbf6ec
Showing
2 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {ICircuitValidator} from "../interfaces/ICircuitValidator.sol"; | ||
|
||
contract ValidatorTestWrapper { | ||
ICircuitValidator public validator; | ||
|
||
constructor(address _verifier) { | ||
validator = ICircuitValidator(_verifier); | ||
} | ||
|
||
/// @return r bool true if proof is valid | ||
function verify( | ||
uint256[] calldata inputs, | ||
uint256[2] calldata a, | ||
uint256[2][2] calldata b, | ||
uint256[2] calldata c, | ||
bytes calldata data | ||
) public returns (bool r) { | ||
bytes4 selector = validator.verify.selector; | ||
bytes memory data = abi.encodePacked(selector, abi.encode(inputs, a, b, c, data), msg.sender); | ||
Check failure on line 22 in contracts/test-helpers/ValidatorTestWrapper.sol
|
||
(bool success, bytes memory returnData) = address(validator).call(data); | ||
if (!success) { | ||
if (returnData.length > 0) { | ||
// Extract revert reason from returnData | ||
assembly { | ||
let returnDataSize := mload(returnData) | ||
revert(add(32, returnData), returnDataSize) | ||
} | ||
} else { | ||
revert("Failed to verify proof without revert reason"); | ||
} | ||
} | ||
return success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters