Skip to content

Commit

Permalink
This commit modifies the WebAuthn library to accept non-calldata Q
Browse files Browse the repository at this point in the history
parameters (since it is common for those to either be read from
storage or immutables).

An overload is provided to maintain backwards compatibility.

Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
Co-authored-by: Mikhail Mikheev <mikhail@safe@global>
  • Loading branch information
3 people committed Dec 13, 2023
1 parent e2830cb commit 1b450b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion solidity/src/FCL_Webauthn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,27 @@ library FCL_WebAuthn {
uint256 clientChallengeDataOffset,
uint256[2] calldata rs,
uint256[2] calldata Q
) internal view returns (bool) {
return checkSignature(authenticatorData, authenticatorDataFlagMask, clientData, clientChallenge, clientChallengeDataOffset, rs, Q[0], Q[1]);
}

function checkSignature (
bytes calldata authenticatorData,
bytes1 authenticatorDataFlagMask,
bytes calldata clientData,
bytes32 clientChallenge,
uint256 clientChallengeDataOffset,
uint256[2] calldata rs,
uint256 Qx,
uint256 Qy
) internal view returns (bool) {
// Let the caller check if User Presence (0x01) or User Verification (0x04) are set

bytes32 message = FCL_WebAuthn.WebAuthn_format(
authenticatorData, authenticatorDataFlagMask, clientData, clientChallenge, clientChallengeDataOffset, rs
);

bool result = FCL_ecdsa_utils.ecdsa_verify(message, rs, Q);
bool result = FCL_ecdsa_utils.ecdsa_verify(message, rs, Qx, Qy);

return result;
}
Expand Down
8 changes: 5 additions & 3 deletions solidity/src/FCL_ecdsa_utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ library FCL_ecdsa_utils {
* @dev ECDSA verification, given , signature, and public key.
*/

function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256[2] calldata Q) internal view returns (bool) {
function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256 Qx, uint256 Qy) internal view returns (bool) {
uint256 r = rs[0];
uint256 s = rs[1];
if (r == 0 || r >= FCL_Elliptic_ZZ.n || s == 0 || s >= FCL_Elliptic_ZZ.n) {
return false;
}
uint256 Qx = Q[0];
uint256 Qy = Q[1];
if (!FCL_Elliptic_ZZ.ecAff_isOnCurve(Qx, Qy)) {
return false;
}
Expand All @@ -60,6 +58,10 @@ library FCL_ecdsa_utils {
return x1 == 0;
}

function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256[2] calldata Q) internal view returns (bool) {
return ecdsa_verify(message, rs, Q[0], Q[1]);
}

function ec_recover_r1(uint256 h, uint256 v, uint256 r, uint256 s) internal view returns (address)
{
if (r == 0 || r >= FCL_Elliptic_ZZ.n || s == 0 || s >= FCL_Elliptic_ZZ.n) {
Expand Down

0 comments on commit 1b450b9

Please sign in to comment.