Comments (4)
@pcaversaccio Exactly, will create the PR for it soon 👍
from snekmate.
@YamenMerhi thanks for sharing the details about your idea. Your idea addresses the composability of the code. While I do see the intent of your issue, I don't think this is the right approach to solve this. Let me explain why:
Case 1: Only ECDSA Support
Devs can use the ECDSA
contract.
Case 2: Support of ECDSA & EIP-1271
Devs can use the SignatureChecker
contract.
Case 3: Only EIP-1271 Support
Devs can use the SignatureChecker
contract with a simple is_contract
check beforehand and making the function _is_valid_signature_now
internal
or simply using the external
function via a simple interface:
Option 1: internal
function approach
@external
@view
def is_valid_ERC1271_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
if (signer.is_contract):
return self._is_valid_signature_now(signer, hash, signature)
return False
@internal
@view
def _is_valid_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
# First check: ECDSA case.
recovered: address = self._recover_sig(hash, signature)
if (recovered == signer):
return True
# Second check: EIP-1271 case.
return_data: Bytes[32] = \
raw_call(signer, _abi_encode(hash, signature, method_id=IERC1271_ISVALIDSIGNATURE_SELECTOR), max_outsize=32, is_static_call=True)
return ((len(return_data) == 32) and (convert(return_data, bytes32) == convert(IERC1271_ISVALIDSIGNATURE_SELECTOR, bytes32)))
Option 2: external
function approach
interface SignatureChecker:
def is_valid_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool: view
@external
@view
def is_valid_ERC1271_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
if (signer.is_contract):
return SignatureChecker(self).is_valid_signature_now(signer, hash, signature)
return False
The contract SignatureChecker
is a superset of ECDSA
& EIP-1271
and is already composable if you need to strictly make a EIP-1271
check. Would agree with this or why exactly do you see a specific need to solve this via a separate internal
function?
from snekmate.
I think after reflecting on your proposal, it would make sense to add two functions:
is_valid_ERC1271_signature_now
(external
) that simply calls the followinginternal
function_is_valid_ERC1271_signature_now
(internal
)
_is_valid_ERC1271_signature_now
can be re-used in is_valid_signature_now
.
@external
@view
def is_valid_ERC1271_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
return self._is_valid_ERC1271_signature_now(signer, hash, signature)
@internal
@view
def _is_valid_ERC1271_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
return_data: Bytes[32] = \
raw_call(signer, _abi_encode(hash, signature, method_id=IERC1271_ISVALIDSIGNATURE_SELECTOR), max_outsize=32, is_static_call=True)
return ((len(return_data) == 32) and (convert(return_data, bytes32) == convert(IERC1271_ISVALIDSIGNATURE_SELECTOR, bytes32)))
@external
@view
def is_valid_signature_now(signer: address, hash: bytes32, signature: Bytes[65]) -> bool:
# First check: ECDSA case.
recovered: address = self._recover_sig(hash, signature)
if (recovered == signer):
return True
# Second check: EIP-1271 case.
return self._is_valid_ERC1271_signature_now(signer, hash, signature)
Feel free to open a PR on that including the necessary test cases.
from snekmate.
awesome thx
from snekmate.
Related Issues (20)
- 👷♂️ Implement CI Tests for User Documentation `userdoc` and Developer Documentation `devdoc` HOT 2
- 📖 Add NatSpec Field `@custom:contract-name`
- 💥 `ERC-2981` (NFT Royalty Standard) Implementation HOT 10
- ♻️ Make Test Suite Compatible With Foundry `v1.0` HOT 2
- 🔁 Upgrade to Solidity Version `0.8.21` HOT 4
- 💥 Implement `deployBlueprint` Function in `VyperDeployer` Utility Function HOT 3
- 🔁 Upgrade to Vyper Version `0.3.10`
- ♻️ Remove `increase_allowance` and `decrease_allowance` from `ERC20` and `ERC4626`
- 🔁 Upgrade to Solidity Version `0.8.22`
- 💥 `ERC-4337` Functionalities
- 💥 Add `P256Verifier` to 🐍 snekmate
- 💥 Vyper-Based Multisig Wallet HOT 5
- 💥 `Governor` Contract
- 💥 `TimelockController` Contract HOT 1
- 👷♂️ Add Slither to CI Pipeline
- 💥 Integrate 🐍 snekmate Contracts with Halmos
- 🔁 Upgrade Solidity Version to `0.8.23`
- 💥 Amend `stateful` (a.k.a. `invariant`) Tests
- 🐛 `VyperDeployer` Fails in Forking Mode HOT 10
- 🔁 Upgrade Solidity Version to `0.8.24`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snekmate.