Published on

Understanding User Operations: A Deep Dive into Flexible Transaction Models

Authors

Understanding User Operations: A Deep Dive into Flexible Transaction Models

In the last blog post in this series we took a look at what Account Abstraction(AA) is and some of the use cases enabled by it. In this article, we will dive a little deeper into a big part of how these use cases are possible: User Operations(UserOps).

What Are User Operations?

To recap, UserOps are data objects containing all the information needed to execute a transaction. They can also hold data that allows us to execute additional logic before deciding to complete the transaction. Traditionally EVM transactions are rigid and offer limited flexibility in validating transactions. UserOps can help us set custom rules and conditions for transactions programmatically.

In simple terms, UserOps are like customizable transactions that allow developers to define unique logic for how and when they should be executed. This enables a more flexible and powerful transaction model than the traditional transactions we are accustomed to in blockchains like Ethereum.

How User Operations Work

In ERC-4337, transactions are validated by smart contract code rather than hardcoded rules within the protocol. UserOps are sent to the network, where specialized entities called bundlers push these UserOps to an entry point contract.

The entry point contract is a smart contract that serves as an intermediary. It contains the logic necessary to determine whether the user operation meets the custom conditions defined by the developer. If the conditions are met, the entry point contract processes the transaction accordingly. Here is a simplified version of what a UserOp could look like represented as a JSON object:

{
  "type": "UserOperation",
  "entryPointContract": "0x1234abcd...",
  "payload": {
    "operationType": "TokenTransfer",
    "amount": 50,
    "token": "DAI",
    "recipient": "0x5678efgh..."
  },
  "signature": "0x9876sign...",
  "nonce": 12345
}

Let’s break down what some of these fields mean:

  • "type": Indicates that this JSON object is a User Operation.
  • "entryPointContract": Specifies the address of the entry point contract that should interpret and execute this UserOp.
  • "payload": Contains the details of the operation to be executed. In this example, it's a token transfer of 50 DAI tokens to a recipient address.
  • "signature": A cryptographic signature from the user who initiated the UserOp, to prove the authenticity of the operation.
  • "nonce": A number that prevents replay attacks. This number must be unique for each UserOp sent by a user.

The information in this object refers to an ERC20 token transfer of the stable coin DAI. It is simply giving the direction that we should send 50 Dai to some recipient. Let’s think about this transaction a little more however - there is a friction point that needs to be overcome: as long as the user has sufficient funds in their wallet to cover gas we should expect this transaction to be executed as normal.

Let’s overcome this friction point by adding an additional field to this UserOp:

{
  "type": "UserOperation",
  "entryPointContract": "0x1234abcd...",
  "payload": {
    "operationType": "TokenTransfer",
    "amount": 50,
    "token": "DAI",
    "recipient": "0x5678efgh..."
  },
  "signature": "0x9876sign...",
  "nonce": 12345,
  "paymaster": "0x9abcd123..."
}

You’ll notice now that there is a new field called “paymaster.” The Paymaster is an entity that agrees to pay for the transaction fees on behalf of the user, alternatively it can allow the user to pay for the gas fees using an ERC20 token. So instead of just unlocking the ability to sponsor transactions, simply adding this new field in the UserOp can help us access logic that would allow us to pay for this transfer using any leftover DAI we might have in our wallet aside from the 50 DAI needed for this transfer.

Conclusion

The main takeaway here is this: as long as the information is available on the UserOperation - we can use code to execute any arbitrary logic needed before executing the final transaction.

UserOps are a groundbreaking concept that aims to make Ethereum ands its ecosystem, more user-friendly. Through the utilization of UserOps, not only can we simplify the way transactions are handled but also enable diverse transaction formats, allowing smart contracts to act with more autonomy. The applications of UserOps are still in the early stages, but as the ecosystem evolves, it is expected to bring a paradigm shift in how we execute transactions.