-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR fixes: add comments, rename constracts, more interfaces to contrac…
…t files
- Loading branch information
Showing
31 changed files
with
333 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2024 Lido <info@lido.fi> | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Extracted from: | ||
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/cryptography/ECDSA.sol#L53 | ||
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/541e821/contracts/utils/cryptography/ECDSA.sol#L112 | ||
|
||
pragma solidity 0.8.10; | ||
|
||
library ECDSA { | ||
/** | ||
* @dev Returns the address that signed a hashed message (`hash`). | ||
* This address can then be used for verification purposes. | ||
* Receives the `v`, `r` and `s` signature fields separately. | ||
* | ||
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: | ||
* this function rejects them by requiring the `s` value to be in the lower | ||
* half order, and the `v` value to be either 27 or 28. | ||
* | ||
* IMPORTANT: `hash` _must_ be the result of a hash operation for the | ||
* verification to be secure: it is possible to craft signatures that | ||
* recover to arbitrary addresses for non-hashed data. | ||
*/ | ||
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) | ||
{ | ||
// 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 (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most | ||
// signatures from current libraries generate a unique signature with an s-value in the lower half order. | ||
// | ||
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value | ||
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or | ||
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept | ||
// these malleable signatures as well. | ||
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value"); | ||
Check warning on line 35 in contracts/lib/ECDSA.sol GitHub Actions / solhint
|
||
|
||
// If the signature is valid (and not malleable), return the signer address | ||
address signer = ecrecover(hash, v, r, s); | ||
require(signer != address(0), "ECDSA: invalid signature"); | ||
|
||
return signer; | ||
} | ||
|
||
/** | ||
* @dev Overload of `recover` that receives the `r` and `vs` short-signature fields separately. | ||
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] | ||
*/ | ||
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { | ||
bytes32 s; | ||
uint8 v; | ||
assembly { | ||
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) | ||
v := add(shr(255, vs), 27) | ||
} | ||
return recover(hash, v, r, s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.