Skip to content

Commit

Permalink
fix: auth validity verification when impersoanting, pub keys where used
Browse files Browse the repository at this point in the history
everytime
  • Loading branch information
yum0e committed Jul 2, 2023
1 parent 09fd3ed commit da25dfe
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 149 deletions.
82 changes: 82 additions & 0 deletions src/misc/CheatSheet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "../libs/sismo-connect/SismoConnectLib.sol";

contract CheatSheet is SismoConnect {
// reference your appId
bytes16 public constant APP_ID = 0x32403ced4b65f2079eda77c84e7d2be6;
// allow impersonation
bool public constant IS_IMPERSONATION_MODE = true;

constructor()
// use buildConfig helper to easily build a Sismo Connect config in Solidity
SismoConnect(buildConfig({appId: APP_ID, isImpersonationMode: IS_IMPERSONATION_MODE}))
{}

function verifySismoConnectResponse(bytes memory response) public {
// Recreate the request made in the fontend to verify the proof
AuthRequest[] memory auths = new AuthRequest[](6);
auths[0] = _authRequestBuilder.build({authType: AuthType.VAULT});
auths[1] = _authRequestBuilder.build({authType: AuthType.EVM_ACCOUNT});
auths[2] = _authRequestBuilder.build({
authType: AuthType.EVM_ACCOUNT,
userId: uint160(0xA4C94A6091545e40fc9c3E0982AEc8942E282F38)
});
auths[3] = _authRequestBuilder.build({authType: AuthType.GITHUB});
auths[4] = _authRequestBuilder.build({
authType: AuthType.TWITTER,
userId: 295218901,
isOptional: true,
isSelectableByUser: false
});
auths[5] = _authRequestBuilder.build({
authType: AuthType.TELEGRAM,
userId: 875608110,
isOptional: true,
isSelectableByUser: false
});

ClaimRequest[] memory claims = new ClaimRequest[](6);
claims[0] = _claimRequestBuilder.build({groupId: 0xfae674b6cba3ff2f8ce2114defb200b1});
claims[1] = _claimRequestBuilder.build({
groupId: 0x1cde61966decb8600dfd0749bd371f12,
claimType: ClaimType.GTE,
value: 15
});
claims[2] = _claimRequestBuilder.build({
groupId: 0xfae674b6cba3ff2f8ce2114defb200b1,
claimType: ClaimType.EQ,
value: 10
});
claims[3] = _claimRequestBuilder.build({
groupId: 0x1cde61966decb8600dfd0749bd371f12,
claimType: ClaimType.EQ,
value: 15,
isSelectableByUser: true,
isOptional: true
});
claims[4] = _claimRequestBuilder.build({
groupId: 0xfae674b6cba3ff2f8ce2114defb200b1,
claimType: ClaimType.GTE,
isSelectableByUser: true,
isOptional: true
});
claims[5] = _claimRequestBuilder.build({
groupId: 0x1cde61966decb8600dfd0749bd371f12,
claimType: ClaimType.GTE,
value: 25,
isSelectableByUser: true,
isOptional: false
});

SismoConnectVerifiedResult memory result = verify({
responseBytes: response,
auths: auths,
claims: claims,
signature: _signatureBuilder.build({message: abi.encode("I love Sismo!")})
});

// implement some logic if the proof is successful
}
}
13 changes: 10 additions & 3 deletions src/verifiers/HydraS3Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ contract HydraS3Verifier is IHydraS3Verifier, IBaseVerifier, HydraS3SnarkVerifie
hydraS3Proof.input,
sismoConnectProof.proofData,
auth,
appId
appId,
isImpersonationMode
);
}
if (sismoConnectProof.claims.length == 1) {
Expand Down Expand Up @@ -187,7 +188,8 @@ contract HydraS3Verifier is IHydraS3Verifier, IBaseVerifier, HydraS3SnarkVerifie
HydraS3ProofInput memory input,
bytes memory proofData,
Auth memory auth,
bytes16 appId
bytes16 appId,
bool isImpersonationMode
) private view returns (VerifiedAuth memory) {
uint256 userIdFromProof;
if (auth.authType == AuthType.VAULT) {
Expand All @@ -203,7 +205,12 @@ contract HydraS3Verifier is IHydraS3Verifier, IBaseVerifier, HydraS3SnarkVerifie
revert DestinationVerificationNotEnabled();
}
// commitmentMapperPubKey
uint256[2] memory commitmentMapperPubKey = COMMITMENT_MAPPER_REGISTRY.getEdDSAPubKey();
uint256[2] memory commitmentMapperPubKey = isImpersonationMode
? [
0x1801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b,
0x057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b
]
: COMMITMENT_MAPPER_REGISTRY.getEdDSAPubKey();
if (
input.commitmentMapperPubKey[0] != commitmentMapperPubKey[0] ||
input.commitmentMapperPubKey[1] != commitmentMapperPubKey[1]
Expand Down
Loading

0 comments on commit da25dfe

Please sign in to comment.