AA Workshop:
Account
What are the required functionalities for an Account contract? What to keep in mind when designing your own Account?
Dec 19 2023 | Dapp Learning
Equal access to the Tokenized World
Nic Lin
imToken Labs
What are the required functionalities for an Account?
I will mainly use 4337 examples but most of them apply to native AA too. I will mention the difference if there’s any.
What to keep in mind when designing your own Account?
What are the required functionalities for an Account?
How to pay for your transaction in 4337?
How to pay for your transaction in 4337?
User
Bundler
ETH
ERC20
❌
Proposer
ETH
How to pay for your transaction in 4337?
Transaction payment is made in ETH, just like normal ETH transactions
User
Bundler
ETH
Entrypoint
ETH
How to pay for your transaction in 4337?
User
Entrypoint
ETH
depositTo(User)
ETH
How to pay for your transaction in 4337?
User
Gas price I’m willing to pay
Max gas for my execution
Max gas for validating my transaction
Gas for Entrypoint processing overhead
How to pay for your transaction in 4337?
Entrypoint
User
User’s Account contract
validateUserOp(...)
ETH
Your deposit not enough, please deposit
How to pay for your transaction in 4337?
Entrypoint
User
User’s Account contract
validateUserOp(...)
ETH
Your deposit not enough, please deposit
Bundler
This is my UserOp, I’m willing to pay��`maxFeePerGas *�(callGasLimit + verificationGasLimit + preVerificationGas)` ��ETH for this op.
How to pay for your transaction in 4337?
How to pay for your transaction in 4337?
User
Bundler
ETH
ERC20
Proposer
ETH
Paymaster
ETH
How to pay for your transaction in 4337?
How to validate your transaction in 4337?
How to validate your transaction in 4337?
Entrypoint
User’s Account contract
validateUserOp(...)
returns 0
User authorized 👍
Entrypoint
User’s Account contract
validateUserOp(...)
returns 1 or revert
User did NOT authorize 👎
How to validate your transaction in 4337?
Entrypoint
User’s Account contract
validateUserOp(...)
returns 0
Signature checked.
User authorized 👍
ECDSA
How to validate your transaction in 4337?
Entrypoint
User’s Account contract
validateUserOp(...)
returns 0
User authorized 👍
execute(...)
How to validate your transaction in 4337?
Entrypoint
User’s Account contract
execute(...)
Entrypoint want me to execute, it must have called validateUserOp already
swap
How to validate your transaction in 4337?
User’s Account contract
execute(...)
You are not Entrypoint
❌
How to validate your transaction in 4337?
How to deploy your Account contract in 4337?
How to deploy your Account contract in 4337?
How to deploy your Account contract in 4337?
How to deploy your Account contract in 4337?
How to deploy your Account contract in 4337?
Entrypoint
User
User’s Account contract
Please execute my UserOp
check contract exists
Not exist
How to deploy your Account contract in 4337?
Entrypoint
User
Please deploy my Account contract and execute my UserOp
deploy
Already exist
User’s Account contract
How to deploy your Account contract in 4337?
Entrypoint
User
Please deploy my Account contract, this is the factory address and data to call the factory for my contract deployment
Factory of user’s Account contract
How to deploy your Account contract in 4337?
User
In the initcode field of my UserOp:
UserOp {
…
initcode: [20 bytes factory address][calldata for factory]
…
}
How to deploy your Account contract in 4337?
UserOp {
…
initcode: [20 bytes factory address][calldata for factory]
…
}
For example:
ABI encode of “createAccount(owner,salt)”
How to deploy your Account contract in 4337?
Entrypoint
Bob
Please deploy my Account contract and execute my UserOp
deploy
This is not Bob’s Account contract
Alice’s Account contract
How to deploy your Account contract in 4337?
Bob
Where will my contract be deployed at?
Factory of Bob’s Account contract
getAddress(owner,salt)
How to deploy your Account contract in 4337?
Bob
Where will my contract be deployed at?
Factory of Bob’s Account contract
getAddress(owner,salt)
0x1234beef
How to deploy your Account contract in 4337?
Entrypoint
Bob
Please deploy my Account contract and execute my UserOp
deploy
UserOp {
…
sender: 0x1234beef
initcode: …
…
}
User’s Account contract
Factory of Bob’s Account contract
deploy
How to deploy your Account contract in 4337?
What are the required functionalities for an Account?
What are the required functionalities for an Account?
ETH
ECDSA
=> same as an EOA
e.g., zkSync’s Default Account
What are the required functionalities for an Account?
ETH
ECDSA
=> same as an EOA
e.g., zkSync’s Default Account
Native AA does not support deploy at first transaction :(
What are the required functionalities for an Account?
ETH
ECDSA
=> same as an EOA
e.g., zkSync’s Default Account
Native AA does not support deploy at first transaction :(
Either user needs a deploy transaction or wallet/dApp hides it from UX
e.g., wallet/dApp deploys for user and charges for deployment fee at user’s first transaction
What to keep in mind when designing your own Account?
What to keep in mind when designing your own Account?
What to keep in mind when designing your own Account?
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Add in more features to your Account
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Safety considerations
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
Debugging tips (4337)
What to keep in mind when designing your own Account?
What to keep in mind when designing your own Account?
What to keep in mind when designing your own Account?
Thank you
Apr 24 2023 | POPOP Taipei
Equal access to the Tokenized World