Consistently name multiple returned values (#5177)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
committed by
Hadrien Croubois
parent
22ec876c5a
commit
6c73fcddea
@ -53,7 +53,10 @@ library ECDSA {
|
||||
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
|
||||
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
|
||||
*/
|
||||
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
|
||||
function tryRecover(
|
||||
bytes32 hash,
|
||||
bytes memory signature
|
||||
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
|
||||
if (signature.length == 65) {
|
||||
bytes32 r;
|
||||
bytes32 s;
|
||||
@ -96,7 +99,11 @@ library ECDSA {
|
||||
*
|
||||
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
|
||||
*/
|
||||
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
|
||||
function tryRecover(
|
||||
bytes32 hash,
|
||||
bytes32 r,
|
||||
bytes32 vs
|
||||
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
|
||||
unchecked {
|
||||
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
|
||||
// We do not check for an overflow here since the shift operation results in 0 or 1.
|
||||
@ -123,7 +130,7 @@ library ECDSA {
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) internal pure returns (address, RecoverError, bytes32) {
|
||||
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
|
||||
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
|
||||
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
|
||||
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
|
||||
|
||||
@ -120,7 +120,7 @@ library P256 {
|
||||
* IMPORTANT: This function disallows signatures where the `s` value is above `N/2` to prevent malleability.
|
||||
* To flip the `s` value, compute `s = N - s` and `v = 1 - v` if (`v = 0 | 1`).
|
||||
*/
|
||||
function recovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal view returns (bytes32, bytes32) {
|
||||
function recovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal view returns (bytes32 x, bytes32 y) {
|
||||
if (!_isProperSignature(r, s) || v > 1) {
|
||||
return (0, 0);
|
||||
}
|
||||
@ -136,8 +136,8 @@ library P256 {
|
||||
uint256 w = Math.invModPrime(uint256(r), N);
|
||||
uint256 u1 = mulmod(N - (uint256(h) % N), w, N);
|
||||
uint256 u2 = mulmod(uint256(s), w, N);
|
||||
(uint256 x, uint256 y) = _jMultShamir(points, u1, u2);
|
||||
return (bytes32(x), bytes32(y));
|
||||
(uint256 xU, uint256 yU) = _jMultShamir(points, u1, u2);
|
||||
return (bytes32(xU), bytes32(yU));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,7 +247,11 @@ library P256 {
|
||||
* The individual points for a single pass are precomputed.
|
||||
* Overall this reduces the number of additions while keeping the same number of doublings.
|
||||
*/
|
||||
function _jMultShamir(JPoint[16] memory points, uint256 u1, uint256 u2) private view returns (uint256, uint256) {
|
||||
function _jMultShamir(
|
||||
JPoint[16] memory points,
|
||||
uint256 u1,
|
||||
uint256 u2
|
||||
) private view returns (uint256 rx, uint256 ry) {
|
||||
uint256 x = 0;
|
||||
uint256 y = 0;
|
||||
uint256 z = 0;
|
||||
|
||||
Reference in New Issue
Block a user