Giter Site home page Giter Site logo

Comments (4)

YamenMerhi avatar YamenMerhi commented on June 3, 2024 1

@pcaversaccio Exactly, will create the PR for it soon 👍

from snekmate.

pcaversaccio avatar pcaversaccio commented on June 3, 2024

@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.

pcaversaccio avatar pcaversaccio commented on June 3, 2024

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 following internal 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.

pcaversaccio avatar pcaversaccio commented on June 3, 2024

awesome thx

from snekmate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.