ECDSA256r1

Git Source

A library to verify ECDSA signatures made on the secp256r1 curve

This is the easiest library to deal with but also the most expensive in terms of gas cost. Indeed, this library must calculate multiple points on the curve in order to verify the signature. Use it kmowingly.

Functions

isPointValid

Verifies that a point is on the secp256r1 curve

function isPointValid(uint256 x, uint256 y) internal pure returns (bool);

Parameters

NameTypeDescription
xuint256The x-coordinate of the point
yuint256The y-coordinate of the point

Returns

NameTypeDescription
<none>boolbool True if the point is on the curve, false otherwise

mulmuladd

and Q is the public key.

function mulmuladd(uint256 Q0, uint256 Q1, uint256 scalar_u, uint256 scalar_v) internal returns (uint256 X);

Parameters

NameTypeDescription
Q0uint256x-coordinate of the input point Q
Q1uint256y-coordinate of the input point Q
scalar_uuint256Multiplier for basepoint G
scalar_vuint256Multiplier for input point Q

Returns

NameTypeDescription
Xuint256Resulting x-coordinate of the computed point

verify

Verifies an ECDSA signature on the secp256r1 curve given the message, signature, and public key. This function is the only one exposed by the library

Note the required interactions with the precompled contract can revert the transaction

function verify(bytes32 message, uint256 r, uint256 s, uint256 qx, uint256 qy) internal returns (bool);

Parameters

NameTypeDescription
messagebytes32The original message that was signed
ruint256uint256 The r value of the ECDSA signature.
suint256uint256 The s value of the ECDSA signature.
qxuint256The x value of the public key used for the signature
qyuint256The y value of the public key used for the signature

Returns

NameTypeDescription
<none>boolbool True if the signature is valid, false otherwise