Skip to content
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

Safe 4337 Signer Launchpad #184

Merged
merged 13 commits into from
Dec 13, 2023
Merged

Safe 4337 Signer Launchpad #184

merged 13 commits into from
Dec 13, 2023

Conversation

nlordell
Copy link
Collaborator

@nlordell nlordell commented Dec 6, 2023

Related to #149, follow-up to #182

This PR provides another approach to Safe initialization to accommodate for custom signers that are deployed along with the Safe. See #182 for more context.

This launchpad implementation is very specific to custom signers and introduces a new IUniqueSignerFactory interface that must be implemented to work with it. The name “unique” signer is not great, but named this way since for a given factory and some “signer data”, a ISignatureVerifier implementation will correspond to a unique address. In the example of P-256 and WebAuthn signers, this means a P-256 public key will correspond to a unique on-chain address with an ISignatureVerifier implementation.

This implementation works by tying the Safe address to the signerFactory, signerData and Safe setup parameters. This means a couple of things:

  1. The Safe address is unique for a specific initial configuration (owner, singleton, fallback, modules, etc.); the same property holds for the existing SafeProxyFactory
  2. Unlike Launchpad Contract for ERC-4337-Compatible Initialisation #182, the Safe address is not tied to the first user operation (in fact, the user operation is signed with the same owner as the Safe will use!)
sequenceDiagram
    actor B as Bundler
    participant E as EntryPoint
    participant F as SafeProxyFactory
    participant P as SafeProxy (Account)
    participant L as SafeSignerLaunchpad
    participant S as Safe (Singleton)
    participant M as Safe4337Module
    participant U as IUniqueSignerFactory
    participant A as Signer
    actor T as Target

    B  ->> +E: handleOps([userOp])
    E  ->> +F: CALL(userOp.initCode[:20])
    F  ->>  P: CREATE2
    F  ->>  P: setup(initHash)
    P  ->>  L: setup(initHash)
    note over L: SSTORE(initHash)
    F -->> -E: ok

    E  ->> +P: validateUserOp(userOp)
    P  ->> +L: validateUserOp(userOp)
    note over L: require(getInitHash(userOp) == initHash)
    L  ->> +U: isValidSignatureForSigner(operationData, signature, signerData)
    U -->> -L: magic
    L -->> -P: validationData
    P -->> -E: validationData

    E  ->> +P: initializeThenUserOp<br>(singleton, signerFactory, signerData, ...setupParams, callData)
    P  ->>  L: initializeThenUserOp(…)
    note over L: SafeStorage.singleton = singleton
    L  ->> +U: createSigner(signerData)
    U  ->>  A: CREATE2
    U -->> -L: owner
    L  ->>  S: setup([owner], 1, ...setupParams)
    note over S: standard Safe setup
    L  ->>  P: DELEGATECALL(callData)
    P  ->>  S: DELEGATECALL(callData)
    S  ->>  M: execUserOp(…)
    M  ->>  P: executeFromModule(…)
    P  ->>  S: executeFromModule(…)
    S  ->>  T: Ether
    P -->> -E: ok
Loading

Implementation Notes

Currently, the implementation only supports a single signer, but can be changed to support multiple (by turning signerFactory and signerData into arrays).

Downsides

The downsides of this implementation over #182 is that it is a solution very specific to deploying Safes with custom signing schemes that require additional contract deployments and not a general solution to complex Safe setups in the context of ERC-4337.

@nlordell nlordell requested a review from a team as a code owner December 6, 2023 15:06
@nlordell nlordell requested review from rmeissner, akshay-ap, mmv08 and remedcu and removed request for a team December 6, 2023 15:06
Copy link
Member

@mmv08 mmv08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the PR

4337/contracts/test/SafeSignerLaunchpad.sol Show resolved Hide resolved
4337/contracts/test/SafeSignerLaunchpad.sol Outdated Show resolved Hide resolved
4337/contracts/test/TestUniqueSigner.sol Show resolved Hide resolved
@nlordell nlordell changed the base branch from launchpad-contract to master December 13, 2023 08:55
@coveralls
Copy link

coveralls commented Dec 13, 2023

Pull Request Test Coverage Report for Build 7193084547

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 7180707836: 0.0%
Covered Lines: 33
Relevant Lines: 33

💛 - Coveralls

@nlordell nlordell merged commit 7c725e4 into master Dec 13, 2023
6 checks passed
@nlordell nlordell deleted the launchpad-contract-signer branch December 13, 2023 09:26
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants