latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
737 stars 187 forks source link

Proposal: account delegation via `callFrom` #1358

Closed alvrs closed 1 year ago

alvrs commented 1 year ago

Abstract

This proposal introduces a modular mechanism allowing accounts to delegate other accounts to execute functions on their behalf. By modularizing the delegation logic, we can cater to various use cases, from simple unlimited delegations to complex, conditional ones.

Design Goals

Sample use cases

  1. Session accounts
    • Allow main accounts to delegate a burner wallet with restricted permissions.
    • Set conditions such as the number of calls, specific function access, or duration of the delegation.
    • More use case specific restrictions could be “allow delegation for the duration of this match”
  2. Trusted Forwarder: [EIP-2771](https://eips.ethereum.org/EIPS/eip-2771), where users can authorize their preferred forwarder.
  3. Atomic Operations: Like ERC20's approve + transferFrom mechanism.
    • Ex. 1: Let a user delegate a module to call registerHook without transferring namespace ownership.
    • Ex. 2: Flash lend an army in an onchain strategy game.
  4. Modular Systems: Build higher-level abstractions using pre-existing systems. Refer to https://github.com/latticexyz/mud/issues/319

Proposed solution

Overview

Implementation

Related issues

holic commented 1 year ago

I'm curious about what I imagine will be the most common use case: account delegation from EOA to burner wallet for an indefinite period of time.

I assume this path would mean extra gas via CALL per action/transaction of the burner wallet? Are there ways we can reduce that or is this design already accounting for that?

alvrs commented 1 year ago

account delegation from EOA to burner wallet for an indefinite period of time.

if the delegation is not limited to certain functions, the UNLIMITED_DELEGATION can be used and no additional CALL would be required. If it should be limited to certain functions it would have to happen via a CALL to a delegation check in the current design. There is some overhead in that, but there are simply too many variants of limitations to hardcode some of them in the core function (eg. limit to all functions of a namespace, limit to all functions of a system, limit to a specific function, limit to a specific function with specific arguments). If the check happens via a CALL the respective delegation check system can just perform the checks that are actually required, which saves some gas over doing more checks in the core function that might not be relevant for the specific type of limitation.

holic commented 1 year ago

Ohh got it! I glossed over the unlimited delegation bit. 👌

ludns commented 1 year ago

from your perspective, what would be the most "ERC-4337" native way of doing this? The answer might be that there can't be any overlap and we have to roll everything on our own (apart from the trusted forwarder standard) and that's ok. But I am curious if there ways to re-use some of the infrastructure, like bundlers. Have you took a look at the spec?

alvrs commented 1 year ago

from your perspective, what would be the most "ERC-4337" native way of doing this? The answer might be that there can't be any overlap and we have to roll everything on our own (apart from the trusted forwarder standard) and that's ok. But I am curious if there ways to re-use some of the infrastructure, like bundlers. Have you took a look at the spec?

In my mind this proposal is mostly orthogonal to ERC-4337. There are some overlapping use cases (e.g. “session wallets” could also be implemented as a type of 4337 account), but other use cases are different. Most notably the use case of temporary approvals for specific function calls isn’t really a design goal of 4337, while it’s one of the core design goals of callFrom (i.e. support “atomic swaps” with any system akin to ERC-20’s approve/transferFrom pattern, or allow modules to set up stuff in your name, or allow a system to call other lower level systems in your name). It would definitely be possible to create a 4337 account that implements logic to temporarily delegate access to certain functions to other accounts, but it wouldn’t be the most straightforward solution, and it would be outside the MUD protocol, so other protocol features couldn’t build on top of it.