-
Notifications
You must be signed in to change notification settings - Fork 75
EIP-1271 #80
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
Open
thrilok209
wants to merge
7
commits into
master
Choose a base branch
from
EIP-1271
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EIP-1271 #80
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
42f624b
EIP-1271
thrilok209 2999693
Update contracts/v2/accounts/default/implementation_default.sol
thrilok209 a85466e
Check signedMessage if signature doesn't match
thrilok209 f8b73bf
minor change
thrilok209 d1b83f1
converted chainId to immutable
thrilok209 a5531a5
deployment script
thrilok209 d78c9ff
Updated addresses.json
thrilok209 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,99 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.7.0; | ||
|
|
||
| /** | ||
| * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. | ||
| * | ||
| * These functions can be used to verify that a message was signed by the holder | ||
| * of the private keys of a given address. | ||
| */ | ||
| library ECDSA { | ||
| /** | ||
| * @dev Returns the address that signed a hashed message (`hash`) with | ||
| * `signature`. This address can then be used for verification purposes. | ||
| * | ||
| * 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. A safe way to ensure | ||
| * 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) { | ||
| // Check the signature length | ||
| if (signature.length != 65) { | ||
| revert("ECDSA: invalid signature length"); | ||
| } | ||
|
|
||
| // Divide the signature in r, s and v variables | ||
| bytes32 r; | ||
| bytes32 s; | ||
| uint8 v; | ||
|
|
||
| // ecrecover takes the signature parameters, and the only way to get them | ||
| // currently is to use assembly. | ||
| // solhint-disable-next-line no-inline-assembly | ||
| assembly { | ||
| r := mload(add(signature, 0x20)) | ||
| s := mload(add(signature, 0x40)) | ||
| v := byte(0, mload(add(signature, 0x60))) | ||
| } | ||
|
|
||
| return recover(hash, v, r, s); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Overload of {ECDSA-recover} that receives the `v`, | ||
| * `r` and `s` signature fields separately. | ||
| */ | ||
| 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"); | ||
| require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value"); | ||
|
|
||
| // 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 Returns an Ethereum Signed Message, created from a `hash`. This | ||
| * produces hash corresponding to the one signed with the | ||
| * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] | ||
| * JSON-RPC method as part of EIP-191. | ||
| * | ||
| * See {recover}. | ||
| */ | ||
| 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)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns an Ethereum Signed Typed Data, created from a | ||
| * `domainSeparator` and a `structHash`. This produces hash corresponding | ||
| * to the one signed with the | ||
| * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] | ||
| * JSON-RPC method as part of EIP-712. | ||
| * | ||
| * See {recover}. | ||
| */ | ||
| function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { | ||
| return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.