Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept elementary types for Q #48

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions solidity/tests/WebAuthn_forge/script/DeployElliptic.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ contract FCL_all_wrapper {
contract MyScript is BaseScript {
function run() external broadcast returns (address addressOfLibrary) {
// deploy the library contract and return the address
addressOfLibrary = address(new FCL_ecdsa_wrapper{salt:0}());
addressOfLibrary = address(new FCL_ecdsa_wrapper{salt: 0}());
}
}

contract Script_Deploy_FCL_all is BaseScript {
function run() external broadcast returns (address addressOfLibrary) {
// deploy the library contract and return the address
addressOfLibrary = address(new FCL_all_wrapper{salt:0}());
addressOfLibrary = address(new FCL_all_wrapper{salt: 0}());
Comment on lines +89 to +96
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record, those changes were required to pass the formatting verification on the CI.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem that the private key operation is at stake, i just added a test vector for multiplication on the edge case here:
#49

Running 1 test for test/FCL_ecmulmul_edge.t.sol:edgemultTest
[PASS] test_edgeMul() (gas: 189600)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.90ms

Trace must be further analyzed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

Expand Down
Loading