Skip to content

Check for msg.sender.code.length before the account is deployed #603

@gabrielstoica

Description

@gabrielstoica

Hi!

I'm trying to make a call to a method in a contract that's guarded by a modifier which checks if the sender (ERC-4337 SA) is a valid non-zero code size contract, as follows:

    /// @dev Allow only calls from contracts implementing the {ISpace} interface
    modifier onlySpace() {
        // Checks: the sender is a valid non-zero code size contract
        if (msg.sender.code.length == 0) {
            revert SpaceZeroCodeSize();
        }

        // Checks: the sender implements the ERC-165 interface required by {ISpace}
        bytes4 interfaceId = type(ISpace).interfaceId;
        if (!ISpace(msg.sender).supportsInterface(interfaceId)) revert SpaceUnsupportedInterface();
        _;
    }

, where ISpace is our own ERC-4337 compliant implementation.

When calling the method for the first time, due to the fact that the account is not deployed yet, it will fail with SpaceZeroCodeSize(). Therefore, we first need to send an empty UserOp to deploy and then call the target method. This adds some traction to the overall workflow.

Is there a better way or workaround to address this behavior e.g. bypassing the initial validation? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions