本文介绍了ERC-7579,一种最小化的模块化智能合约账户实现,它通过定义不同类型的模块(如验证模块、Hook 模块)和账户规范,简化了账户的互操作性和开发门槛。ERC-7579可以与ERC-4337集成,允许EOA直接操作账户,并通过安装第三方模块扩展账户功能。
ERC-7579 定義了最低限度的模組化合約簽包實作,與 ERC-6900 相比簡化了大量的邏輯,以保證 interoperability 和開發門檻,以避免生態被限制於單獨的錢包開發商
ERC-7579 定義了幾個不同類型的模組,未來也可以規劃其他 ERC 進行擴充
所有的模組都必須實作 IERC7579Module interface
interface IERC7579Module {
function onInstall(bytes calldata data) external;
function onUninstall(bytes calldata data) external;
function isModuleType(uint256 moduleTypeId) external view returns(bool);
}
驗證模組還需實作 IERC7579Validator interface
interface IERC7579Validator is IERC7579Module {
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) external returns (uint256);
function isValidSignatureWithSender(
address sender,
bytes32 hash,
bytes calldata signature
) external view returns (bytes4);
}
Hook 模組還需實作 IERC7579Hook interface
interface IERC7579Hook is IERC7579Module {
function preCheck(
address msgSender,
uint256 value,
bytes calldata msgData
) external returns (bytes memory hookData);
function postCheck(bytes calldata hookData) external;
}
Join Medium for free to get updates from this writer.
一個 Account 需要實作 IERC7579Execution interface 以執行交易
interface IERC7579Execution {
function execute(bytes32 mode, bytes calldata executionCalldata) external;
function executeFromExecutor(bytes32 mode, bytes calldata executionCalldata)
external
returns (bytes[] memory returnData);
// optional
function executeUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external;
}
這裡 bytes32 mode 是一些執行資訊的 encode,其 format 如下:
比較重要的是 CallType,定義了 transaction 是以 staticcall, single-call, batch-call 還是 delegatecall 來執行。ExecType 則定義了 transaction 執行後,遇到錯誤的處理方式。
一個 Account 需要實作 IERC7579AccountConfig interface 以提供 account 相關的資訊
interface IERC7579AccountConfig {
function accountId() external view returns (string memory accountImplementationId);
function supportsExecutionMode(bytes32 encodedMode) external view returns (bool);
function supportsModule(uint256 moduleTypeId) external view returns (bool);
}
一個 ERC-7579 Account 需要實作 IERC7579ModuleConfig interface 用以管理模組
interface IERC7579ModuleConfig {
event ModuleInstalled(uint256 moduleTypeId, address module);
event ModuleUninstalled(uint256 moduleTypeId, address module);
function installModule(uint256 moduleTypeId, address module, bytes calldata initData) external;
function uninstallModule(uint256 moduleTypeId, address module, bytes calldata deInitData) external;
function isModuleInstalled(
uint256 moduleTypeId,
address module,
bytes calldata additionalContext
) external view returns (bool);
}
ERC-7579 Account 具體的 execution flow 簡略如下,可以和 ERC-4337 整合,可以以 EOA 直接操作 Account,也可以安裝第三方模組擴充 Account 的功能。整合上的 interface 也十分單純,方便錢包商和獨立開發者做各種功能的延伸
- 本文转载自: medium.com/taipei-ethere... , 如有侵权请联系管理员删除。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!