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

Decent Paymaster V1 #135

Merged
merged 9 commits into from
Feb 14, 2025
Merged

Decent Paymaster V1 #135

merged 9 commits into from
Feb 14, 2025

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Jan 16, 2025

Closes https://linear.app/decent-labs/issue/ENG-147/gasless-voting-paymaster-contract

Depends on #137, so if you're here for a review, please review that one first.

DecentPaymaster Implementation for Account Abstraction Gasless Voting

This PR implements a paymaster contract that enables DAOs to subsidize specific function calls on whitelisted strategy contracts. The implementation follows EIP-4337 (Account Abstraction) standards and provides a flexible way for DAOs to manage which functions they want to sponsor.

Key Features

  1. Custom BasePaymaster Implementation

    • Created our own version of BasePaymaster.sol instead of using the one from @account-abstraction/contracts
    • Reasons for custom implementation:
      • Compatibility with OpenZeppelin v4 (avoiding conflicts with OZ v5 required by account-abstraction)
      • Support for our proxy-based deployment strategy using ModuleProxyFactory
      • Replaced constructor-based initialization with initializer pattern
      • Modified Ownable implementation to use OZ's upgradeable variant
  2. Strategy Function Whitelisting

    • DAOs can whitelist specific function selectors for specific strategy contracts
    • Fine-grained control over which functions can be sponsored
    • Zero-address checks and array length validation for safety
  3. ERC165 Support

    • Full ERC165 interface detection support
    • Implements IPaymaster and custom IDecentPaymaster interfaces
    • Proper interface inheritance and detection
  4. Robust Validation

    • Validates UserOp calldata format and length
    • Extracts and verifies function selectors and target addresses
    • Ensures only approved function calls are sponsored

Technical Details

  • Uses ModuleProxyFactory for deploying minimal proxies of a master copy
  • Initialization through setUp pattern instead of constructors
    • Inherits from OpenZeppelin's upgradeable contracts where needed
  • Uses custom errors for gas optimization and better error reporting
  • Comprehensive test suite with 100% coverage for new contract

Architectural Decisions

  1. Proxy Pattern

    • Master copy deployment followed by minimal proxy instances
    • Initialization via setUp function instead of constructors
    • Compatible with our existing deployment infrastructure
  2. OpenZeppelin Compatibility

    • Uses OZ v4 instead of v5 required by account-abstraction
    • Modified BasePaymaster to work with our OZ version
    • Maintains consistency with project's dependency structure
  3. Deployment Strategy

    • Follows the project's standard deployment pattern using ModuleProxyFactory
    • Enables gas-efficient proxy deployments
    • Maintains upgradeability pattern consistent with other contracts

Security Considerations

  • All state-changing functions are owner-only
  • Input validation for all external functions
  • No reentrancy vulnerabilities
  • Gas-optimized calldata parsing
  • Proper initialization checks for proxy pattern

Testing

The implementation includes extensive tests covering:

  • Initialization and ownership
  • Function approval management
  • UserOp validation
  • Deposit handling
  • ERC165 interface support
  • Proxy deployment and setup

Dependencies

  • Added @account-abstraction/contracts v0.7.0 (for interfaces only)
  • Uses OpenZeppelin v4 contracts for standard implementations
  • Maintains compatibility with existing project dependencies

Copy link

linear bot commented Feb 11, 2025

@adamgall adamgall changed the title Decent paymaster Decent Paymaster V1 Feb 13, 2025
@adamgall
Copy link
Member Author

I'm actually going to just merge this as-is right now, so it doesn't get in my way as I tear apart this codebase for the refactoring and rebuilding work that I need to do on the "long term" contracts.

@adamgall adamgall merged commit cc73219 into develop Feb 14, 2025
3 checks passed
@adamgall adamgall deleted the decent-paymaster branch February 14, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant