Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
disenotov committed Jul 27, 2021
1 parent fd5e35a commit 7e688fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions exchange-v2/contracts/OrderValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "@openzeppelin/contracts-upgradeable/drafts/EIP712Upgradeable.sol";
abstract contract OrderValidator is Initializable, ContextUpgradeable, EIP712Upgradeable {
using LibSignature for bytes32;
using AddressUpgradeable for address;

bytes4 constant internal MAGICVALUE = 0x1626ba7e;

function __OrderValidator_init_unchained() internal initializer {
Expand Down
43 changes: 31 additions & 12 deletions exchange-v2/contracts/lib/LibSignature.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ library LibSignature {
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
function recover(bytes32 hash, bytes memory signature)
internal
pure
returns (address)
{
// Check the signature length
if (signature.length != 65) {
revert("ECDSA: invalid signature length");
Expand All @@ -44,7 +48,12 @@ library LibSignature {
* @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
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
Expand All @@ -54,17 +63,21 @@ library LibSignature {
// 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");

require(
uint256(s) <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
"ECDSA: invalid signature 's' value"
);

// If the signature is valid (and not malleable), return the signer address
// v > 30 is a special case, we need to adjust hash with "\x19Ethereum Signed Message:\n32"
// and v = v - 4



address signer;
if (v > 30){
require(v - 4 == 27 || v - 4 == 28, "ECDSA: invalid signature 'v' value");
if (v > 30) {
require(
v - 4 == 27 || v - 4 == 28,
"ECDSA: invalid signature 'v' value"
);
signer = ecrecover(toEthSignedMessageHash(hash), v - 4, r, s);
} else {
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
Expand All @@ -84,10 +97,16 @@ library LibSignature {
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
function toEthSignedMessageHash(bytes32 hash)
internal
pure
returns (bytes32)
{
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
return
keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
);
}

}

0 comments on commit 7e688fb

Please sign in to comment.