1. 引言
前序博客:
2021年提出提案EIP-4337:Account Abstraction via Entry Point Contract specification,用于实现账号抽象(Account Abstraction,AA),而无需在共识层进行调整。
开源代码实现见:
- https://github.com/eth-infinitism/account-abstraction(Solidity + TypeScript)
Entry Point合约已于2023年2月审计完成,具体见审计报告,当前已在以太坊主网、Goerli、Gnosis chain(以太坊侧链)、Polygon、Optimism、Arbitrum、Base、BNB等上部署。
- https://etherscan.io/address/0x0576a174D229E3cFA37253523E645A78A0C91B57(老版本Entry Point合约0.5,2023年2月23日)
- https://etherscan.io/address/0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789(新版本0.6,合约代码有小调整,2023年4月9日)
ERC4337为智能合约钱包的标准,又名智能账号。其关键特性为:
- 1)用户使用名为UserOperations(UserOps)的伪交易。
- 用户:为Account Abstraction Wallet,即AA钱包。
- AA钱包:为智能合约。为可处理UserOp的智能合约钱包。
- UserOperations(UserOps):为描述“交易”的结构,由Bundler代替用户打包发送到链上。
- 用户:为Account Abstraction Wallet,即AA钱包。
- 2)Bundlers将一组UserOps打包,通过发送EOA交易提交到链上。
- Bundler:为EOA账号。
- 3)Apps可使用Paymasters来替其用户支付gas。
- Paymaster:为智能合约。代替用户支付UserOp gas费。
当前的AA数据统计平台有:
当前ERC-4337的使用情况并不理想,有数据显示,当前ERC-4337的智能账户的用户减少,交易活动减少,核心基础设施提供商的运营成本也很低。【其中七八月份有个高峰,是用户用CyberConnect撸空投。】
根据 BundleBear所统计的账号抽象数据 以及 John Rising twitter 可知:
- 每月的智能账户留存率“很糟糕”,只有6.89%的初始智能账户留存了六个月以上。
- bundlers——支持智能账户功能的核心基础设施,其目前是不盈利的,除非有项目偶尔给bundlers支付了过多的gas。
- 每个智能账户平均只发送了5笔UserOperations(UserOps)。
不过Coinbase protocols lead指出,尽管目前数据不容乐观,但新技术的采纳是“slowly, then suddenly”的。
当前AA应用层基础设施有:
- Infinitism (Smart Account Contract, Bundler, Paymaster)。开源代码见:
- https://github.com/eth-infinitism(TypeScript实现的Bundler)
- Biconomy (Smart Account Contract, Bundler, Paymaster, SDK)。开源代码见:
- https://github.com/bcnmy(TypeScript实现的Bundler)
- StackUp (Smart Account Contract, Bundler, Paymaster, SDK)。开源代码见:
- https://github.com/stackup-wallet(Go实现的Bundler)
- Nethermind(Bundler)。开源代码见:
- https://github.com/NethermindEth/AA_bundler(Go实现的Bundler)
- Etherspot(Bundler, SDK)。开源代码见:
- https://github.com/etherspot/skandha(TypeScript实现的Bundler)
- Safe (Smart Account Contract, SDK)。开源代码见:
- https://github.com/safe-global(TypeScript和Python)
- Web3Auth (Key management)。开源代码见:
- Particle Network(Bundler)。开源代码见:
- Pimlico(Paymaster,Bundler)。开源代码见:
- https://github.com/pimlicolabs/erc20-paymaster-contracts(Solidity)
- https://github.com/pimlicolabs/alto(TypeScript实现的Bundler)
- 等等。
基于AA构建的钱包有:
- Safe (based on Safe)
- Worldcoin (based on Safe)
- Ambire
- Sequence
- Pluser (beta, based on Safe)
- Sout wallet (beta, based on Safe)
- 等等。
当前原生支持AA的L2有:
- zkSync
- Starknet
基于其上构建的钱包有:
- Argent (ZkSync and Starknet)
- Raise Finance (beta, ZkSync)
参考资料
[1] 2023年11月14日 New figures show hardly anyone is using ERC-4337 smart accounts
[2] 2023年9月12日 Smart Accounts Take Off in Q3 (ERC-4337 Statistics)
[3] 2023年11月20日 ERC-4337 Smart Accounts Usage Fails to Gain Traction
[4] 2023年11月14日 Account Abstraction - Current and Future Development on BNB Chain: Part One
[5] 2023年9月9日 A complete guide on account abstraction
[6] 2023年8月14日 Account Abstraction: Solutions for L1 & L2 Layers and Current State of Adoption
[7] 2023年11月8日 The Current State of Account Abstraction | Holdstation
[8] 2023年6月26日 Intro to Account Abstraction: What are paymasters?
[9] 2023年4月4日 Ethereum ERC-4337 ‘bundlers’ — How hard is joining the network?
[10] 2022年4月19日 An Introduction to the Web3 Transaction Lifecycle
[11] Meeting Recap: Bundler P2P Specification
附录:AA背景知识
以太坊之前主要有2大类账号:
而借助AA,可将每个EOA用户账号,抽象为包含高级逻辑的智能合约:
通过ERC-4337,相当于为当前的以太坊EOA交易流程引入"User Intent Layer"。
借助AA:
- 1)【提升用户体验】用户无需对单个意图进行多次签名,可对多个action进行batch-sign:
- 2)【提升用户体验】支持gasless交易,可使用paymaster来代替用户支付gas费:
- 3)【提升用户体验】支持用户以ERC20 token(如USDC),而不是ETH来支付gas费:
- 4)【提升安全性】支持私钥丢失时的社交恢复。
- 5)【提升安全性】支持量子安全的签名算法。
用户发送UserOperation
对象,在UserOperation
对象中打包了:
- 用户意图
- 签名
- 其它验证所需数据
而用户资产存储在Contract Account合约内。bundler程序中eth_sendUserOperation
RPC接口用于向User Operation Mempool中发送UserOperation
对象。
UserOperation
对象与交易类似,为ABI编码结构,包含的字段有:
- sender:执行该操作的钱包
- nonce和签名:传入到钱包验证函数的参数,这样钱包可验证该操作。
- initCode:若钱包不存在,为创建该钱包的初始代码。
- callData:实际执行时调用该钱包的数据。
- 剩下的字段与gas和fee管理有关。
钱包(Contract Account)是一个智能合约,需有2个函数:
- validateUserOp()函数:以
UserOperation
为输入。该函数会验证UserOperation
中的签名和nonce,若验证通过,支付手续费并递增nonce;若验证失败则抛出异常。 UserOperation
执行函数:将UserOperation
中的callData解析为某指令供钱包行动。该函数如何解析Calldata,并对解析结果采取哪种行动是完全开放式的。最常用的情况是将Calldata解析为某指令,钱包据此来发起一次或多次call。
为简化钱包逻辑,确保许多复杂的智能合约安全所需的技巧不是在钱包自身中完成的,而是在一个称为entry point的全局合约中完成的。validateUserOp()函数 和 执行函数 需满足require(msg.sender == ENTRY_POINT)
调用条件。即,仅trusted entry point可调用钱包执行某种action或支付手续费。entry point仅在UserOperation
中的callData已执行成功时才调用钱包的validateUserOp()函数的,因此这样足以避免钱包遭受攻击。若钱包还不存在,entry point也会使用所提供的initCode来创建钱包。
EntryPoint合约需实现的接口函数有:【EntryPoint合约必须被每个人信任。】
account合约需实现的接口有: