-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Make
SignatureChecker
Module-Friendly (#228)
### 🕓 Changelog This PR refactors the `SignatureChecker` contract to make it module-friendly and ready for the breaking `0.4.0` release. Please note that `SignatureChecker` is now [EIP-7377](https://eips.ethereum.org/EIPS/eip-7377)-safe. Furthermore, I add a custom interface `IERC1271` for usage via [EIP-1271](https://eips.ethereum.org/EIPS/eip-1271). --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
- Loading branch information
1 parent
7d2a4e7
commit 40a74ab
Showing
7 changed files
with
159 additions
and
129 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# pragma version ~=0.4.0b6 | ||
""" | ||
@title EIP-1271 Interface Definition | ||
@custom:contract-name IERC1271 | ||
@license GNU Affero General Public License v3.0 only | ||
@author pcaversaccio | ||
@notice The ERC-1271 standard defines a method by which any | ||
contract can verify whether a signature on behalf of | ||
a particular contract is valid. The ERC-165 identifier | ||
for this interface is `0x1626BA7E`. For more details, | ||
please refer to: | ||
https://eips.ethereum.org/EIPS/eip-1271#specification. | ||
|
||
On how to use interfaces in Vyper, please visit: | ||
https://vyper.readthedocs.io/en/latest/interfaces.html#interfaces. | ||
""" | ||
|
||
|
||
@external | ||
@view | ||
def isValidSignature(_hash: bytes32, _signature: Bytes[65]) -> bytes4: | ||
""" | ||
@dev Returns the 4-byte magic value `0x1626BA7E` if the | ||
verification passes. | ||
@param _hash The 32-byte message digest that was signed. | ||
@param _signature The secp256k1 64/65-byte signature of `_hash`. | ||
@return bytes4 The 4-byte magic value. | ||
""" | ||
return ... |
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,79 @@ | ||
# pragma version ~=0.4.0b6 | ||
""" | ||
@title SignatureChecker Module Reference Implementation | ||
@custom:contract-name SignatureCheckerMock | ||
@license GNU Affero General Public License v3.0 only | ||
@author pcaversaccio | ||
""" | ||
|
||
|
||
# @dev We import and initialise the `SignatureChecker` module. | ||
from .. import SignatureChecker as sc | ||
initializes: sc | ||
|
||
|
||
# @dev We export (i.e. the runtime bytecode exposes these | ||
# functions externally, allowing them to be called using | ||
# the ABI encoding specification) the `external` getter | ||
# function `IERC1271_ISVALIDSIGNATURE_SELECTOR` from the | ||
# `SignatureChecker` module. | ||
# @notice Please note that you must always also export (if | ||
# required by the contract logic) `public` declared `constant`, | ||
# `immutable`, and state variables, for which Vyper automatically | ||
# generates an `external` getter function for the variable. | ||
exports: sc.IERC1271_ISVALIDSIGNATURE_SELECTOR | ||
|
||
|
||
@deploy | ||
@payable | ||
def __init__(): | ||
""" | ||
@dev To omit the opcodes for checking the `msg.value` | ||
in the creation-time EVM bytecode, the constructor | ||
is declared as `payable`. | ||
""" | ||
sc.__init__() | ||
|
||
|
||
@external | ||
@view | ||
def is_valid_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool: | ||
""" | ||
@dev Checks if a signature `signature` is valid | ||
for a given `signer` and message digest `hash`. | ||
If the signer is a smart contract, the signature | ||
is validated against that smart contract using | ||
EIP-1271, otherwise it's validated using {ECDSA-_recover_sig}. | ||
@notice Unlike ECDSA signatures, contract signatures | ||
are revocable and the result of this function | ||
can therefore change over time. It could return | ||
`True` in block N and `False` in block N+1 (or the opposite). | ||
@param hash The 32-byte message digest that was signed. | ||
@param signature The maximum 65-byte signature of `hash`. | ||
@return bool The verification whether `signature` is valid | ||
for the provided data. | ||
@custom:security Since we avoid validating ECDSA signatures | ||
when code is deployed at the signer's address, | ||
it is safe if EIP-7377 (https://eips.ethereum.org/EIPS/eip-7377) | ||
should be deployed one day. | ||
""" | ||
return sc._is_valid_signature_now(signer, hash, signature) | ||
|
||
|
||
@external | ||
@view | ||
def is_valid_ERC1271_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool: | ||
""" | ||
@dev Checks if a signature `signature` is valid | ||
for a given `signer` and message digest `hash`. | ||
The signature is validated using EIP-1271. | ||
@notice Unlike ECDSA signatures, contract signatures | ||
are revocable and the result of this function | ||
can therefore change over time. It could return | ||
`True` in block N and `False` in block N+1 (or the opposite). | ||
@param hash The 32-byte message digest that was signed. | ||
@param signature The maximum 65-byte signature of `hash`. | ||
@return bool The verification whether `signature` is valid | ||
for the provided data. | ||
""" | ||
return sc._is_valid_ERC1271_signature_now(signer, hash, signature) |
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