Skip to content

Commit

Permalink
feat: use view function for verify
Browse files Browse the repository at this point in the history
  • Loading branch information
leosayous21 committed Jul 22, 2023
1 parent b45c94a commit 715d52e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/SismoConnectVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract SismoConnectVerifier is ISismoConnectVerifier, Initializable, Ownable {
SismoConnectResponse memory response,
SismoConnectRequest memory request,
SismoConnectConfig memory config
) external override returns (SismoConnectVerifiedResult memory) {
) external view override returns (SismoConnectVerifiedResult memory) {
if (response.appId != config.appId) {
revert AppIdMismatch(response.appId, config.appId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IBaseVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface IBaseVerifier {
bool isImpersonationMode,
bytes memory signedMessage,
SismoConnectProof memory sismoConnectProof
) external returns (VerifiedAuth memory, VerifiedClaim memory);
) external view returns (VerifiedAuth memory, VerifiedClaim memory);
}
2 changes: 1 addition & 1 deletion src/interfaces/ISismoConnectVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ISismoConnectVerifier {
SismoConnectResponse memory response,
SismoConnectRequest memory request,
SismoConnectConfig memory config
) external returns (SismoConnectVerifiedResult memory);
) external view returns (SismoConnectVerifiedResult memory);

function SISMO_CONNECT_VERSION() external view returns (bytes32);
}
50 changes: 25 additions & 25 deletions src/libs/sismo-connect/SismoConnectLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract SismoConnect {
ClaimRequest memory claim,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, claim, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -90,7 +90,7 @@ contract SismoConnect {
AuthRequest memory auth,
ClaimRequest memory claim,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, claim, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -101,7 +101,7 @@ contract SismoConnect {
AuthRequest memory auth,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -112,7 +112,7 @@ contract SismoConnect {
ClaimRequest memory claim,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claim, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -122,7 +122,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest memory auth,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -132,7 +132,7 @@ contract SismoConnect {
bytes memory responseBytes,
ClaimRequest memory claim,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claim, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -143,7 +143,7 @@ contract SismoConnect {
AuthRequest memory auth,
ClaimRequest memory claim,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, claim, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -153,7 +153,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest memory auth,
ClaimRequest memory claim
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, claim);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -163,7 +163,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest memory auth,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -173,7 +173,7 @@ contract SismoConnect {
bytes memory responseBytes,
ClaimRequest memory claim,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claim, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -182,7 +182,7 @@ contract SismoConnect {
function verify(
bytes memory responseBytes,
AuthRequest memory auth
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auth);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -191,7 +191,7 @@ contract SismoConnect {
function verify(
bytes memory responseBytes,
ClaimRequest memory claim
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claim);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -200,7 +200,7 @@ contract SismoConnect {
function verify(
bytes memory responseBytes,
SismoConnectRequest memory request
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
return _sismoConnectVerifier.verify(response, request, config());
}
Expand All @@ -211,7 +211,7 @@ contract SismoConnect {
ClaimRequest[] memory claims,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, claims, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -222,7 +222,7 @@ contract SismoConnect {
AuthRequest[] memory auths,
ClaimRequest[] memory claims,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, claims, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -233,7 +233,7 @@ contract SismoConnect {
AuthRequest[] memory auths,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -244,7 +244,7 @@ contract SismoConnect {
ClaimRequest[] memory claims,
SignatureRequest memory signature,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claims, signature, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -254,7 +254,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest[] memory auths,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -264,7 +264,7 @@ contract SismoConnect {
bytes memory responseBytes,
ClaimRequest[] memory claims,
bytes16 namespace
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claims, namespace);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -275,7 +275,7 @@ contract SismoConnect {
AuthRequest[] memory auths,
ClaimRequest[] memory claims,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, claims, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -285,7 +285,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest[] memory auths,
ClaimRequest[] memory claims
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, claims);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -295,7 +295,7 @@ contract SismoConnect {
bytes memory responseBytes,
AuthRequest[] memory auths,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -305,7 +305,7 @@ contract SismoConnect {
bytes memory responseBytes,
ClaimRequest[] memory claims,
SignatureRequest memory signature
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claims, signature);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -314,7 +314,7 @@ contract SismoConnect {
function verify(
bytes memory responseBytes,
AuthRequest[] memory auths
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(auths);
return _sismoConnectVerifier.verify(response, request, config());
Expand All @@ -323,7 +323,7 @@ contract SismoConnect {
function verify(
bytes memory responseBytes,
ClaimRequest[] memory claims
) internal returns (SismoConnectVerifiedResult memory) {
) internal view returns (SismoConnectVerifiedResult memory) {
SismoConnectResponse memory response = abi.decode(responseBytes, (SismoConnectResponse));
SismoConnectRequest memory request = buildRequest(claims);
return _sismoConnectVerifier.verify(response, request, config());
Expand Down
2 changes: 1 addition & 1 deletion src/misc/CheatSheet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract CheatSheet is SismoConnect {
SismoConnect(buildConfig({appId: _appId, isImpersonationMode: _isImpersonationMode}))
{}

function verifySismoConnectResponse(bytes memory response) public {
function verifySismoConnectResponse(bytes memory response) public view {
// Recreate the request made in the fontend to verify the proof
AuthRequest[] memory auths = new AuthRequest[](6);
auths[0] = _authRequestBuilder.build({authType: AuthType.VAULT});
Expand Down
22 changes: 7 additions & 15 deletions src/verifiers/HydraS3Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract HydraS3Verifier is IHydraS3Verifier, IBaseVerifier, HydraS3SnarkVerifie
bool isImpersonationMode,
bytes memory signedMessage,
SismoConnectProof memory sismoConnectProof
) external returns (VerifiedAuth memory, VerifiedClaim memory) {
) external view returns (VerifiedAuth memory, VerifiedClaim memory) {
// Verify the sismoConnectProof version corresponds to the current verifier.
if (sismoConnectProof.provingScheme != HYDRA_S3_VERSION) {
revert InvalidVersion(sismoConnectProof.provingScheme);
Expand Down Expand Up @@ -288,24 +288,16 @@ contract HydraS3Verifier is IHydraS3Verifier, IBaseVerifier, HydraS3SnarkVerifie
}
}

function _checkSnarkProof(HydraS3ProofData memory snarkProofData) internal {
function _checkSnarkProof(HydraS3ProofData memory snarkProofData) internal view {
// low-level call to the `verifyProof` function
// since the function only accepts arguments located in calldata
(bool success, bytes memory result) = address(this).call(
abi.encodeWithSelector(
this.verifyProof.selector,
snarkProofData.proof.a,
snarkProofData.proof.b,
snarkProofData.proof.c,
snarkProofData.input
)
bool isVerified = this.verifyProof(
snarkProofData.proof.a,
snarkProofData.proof.b,
snarkProofData.proof.c,
snarkProofData.input
);

if (!success) {
revert CallToVerifyProofFailed();
}
bool isVerified = abi.decode(result, (bool));

if (!isVerified) {
revert InvalidProof();
}
Expand Down
10 changes: 5 additions & 5 deletions test/harness/SismoConnectHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,38 @@ contract SismoConnectHarness is SismoConnect {
function exposed_verify(
bytes memory responseBytes,
ClaimRequest memory claim
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
return verify({responseBytes: responseBytes, claim: claim});
}

function exposed_verify(
bytes memory responseBytes,
ClaimRequest memory claim,
bytes16 namespace
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
return verify({responseBytes: responseBytes, claim: claim, namespace: namespace});
}

function exposed_verify(
bytes memory responseBytes,
ClaimRequest memory claim,
SignatureRequest memory signature
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
return verify({responseBytes: responseBytes, claim: claim, signature: signature});
}

function exposed_verify(
bytes memory responseBytes,
AuthRequest memory auth,
SignatureRequest memory signature
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
return verify({responseBytes: responseBytes, auth: auth, signature: signature});
}

function exposed_verify(
bytes memory responseBytes,
SismoConnectRequest memory request
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
return verify({responseBytes: responseBytes, request: request});
}
}
2 changes: 1 addition & 1 deletion test/misc/UpgradeableExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract UpgradeableExample is SismoConnect, Initializable {
function exposed_verify(
bytes memory responseBytes,
SignatureRequest memory signature
) external returns (SismoConnectVerifiedResult memory) {
) external view returns (SismoConnectVerifiedResult memory) {
ClaimRequest[] memory claims = new ClaimRequest[](_groupIds.length);
for (uint256 i = 0; i < _groupIds.length; i++) {
claims[i] = buildClaim(_groupIds[i]);
Expand Down

0 comments on commit 715d52e

Please sign in to comment.