From 64571c53411cffc7a5c60d793e72bcec7a4d1758 Mon Sep 17 00:00:00 2001 From: zer0dot Date: Fri, 31 Jan 2025 15:32:53 -0500 Subject: [PATCH 1/2] feat: 7702 sma --- src/account/SemiModularAccount.sol | 3 ++- src/account/SemiModularAccount7702.sol | 31 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/account/SemiModularAccount7702.sol diff --git a/src/account/SemiModularAccount.sol b/src/account/SemiModularAccount.sol index a72a3603..de8dd87f 100644 --- a/src/account/SemiModularAccount.sol +++ b/src/account/SemiModularAccount.sol @@ -92,7 +92,7 @@ contract SemiModularAccount is ReferenceModularAccount { } /// @inheritdoc IModularAccount - function accountId() external pure override returns (string memory) { + function accountId() external pure virtual override returns (string memory) { return "erc6900.reference-semi-modular-account.0.8.0"; } @@ -177,6 +177,7 @@ contract SemiModularAccount is ReferenceModularAccount { function _retrieveFallbackSignerUnchecked(SemiModularAccountStorage storage _storage) internal view + virtual returns (address) { address storageFallbackSigner = _storage.fallbackSigner; diff --git a/src/account/SemiModularAccount7702.sol b/src/account/SemiModularAccount7702.sol new file mode 100644 index 00000000..6ad09d7a --- /dev/null +++ b/src/account/SemiModularAccount7702.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.20; + +import {IModularAccount} from "../interfaces/IModularAccount.sol"; +import {SemiModularAccount} from "./SemiModularAccount.sol"; +import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; + +contract SemiModularAccount7702 is SemiModularAccount { + constructor(IEntryPoint anEntryPoint) SemiModularAccount(anEntryPoint) {} + + /// @inheritdoc IModularAccount + function accountId() external pure virtual override returns (string memory) { + return "erc6900.reference-semi-modular-account-7702.0.8.0"; + } + + /// @dev If the fallback signer is set in storage, ignore the 7702 signer. + function _retrieveFallbackSignerUnchecked(SemiModularAccountStorage storage _storage) + internal + view + override + returns (address) + { + address storageFallbackSigner = _storage.fallbackSigner; + if (storageFallbackSigner != address(0)) { + return storageFallbackSigner; + } + + // To support 7702, we default to address(this) as the fallback signer. + return address(this); + } +} From f9215cd287391597d5bb4aa7784d5a40c18ca258 Mon Sep 17 00:00:00 2001 From: zer0dot Date: Mon, 3 Feb 2025 13:10:55 -0500 Subject: [PATCH 2/2] feat: block upgrades in 7702 account --- src/account/ReferenceModularAccount.sol | 1 + src/account/SemiModularAccount7702.sol | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/account/ReferenceModularAccount.sol b/src/account/ReferenceModularAccount.sol index 68857ef6..83cf2fac 100644 --- a/src/account/ReferenceModularAccount.sol +++ b/src/account/ReferenceModularAccount.sol @@ -305,6 +305,7 @@ contract ReferenceModularAccount is function upgradeToAndCall(address newImplementation, bytes memory data) public payable + virtual override onlyProxy wrapNativeFunction diff --git a/src/account/SemiModularAccount7702.sol b/src/account/SemiModularAccount7702.sol index 6ad09d7a..e3e08900 100644 --- a/src/account/SemiModularAccount7702.sol +++ b/src/account/SemiModularAccount7702.sol @@ -6,6 +6,8 @@ import {SemiModularAccount} from "./SemiModularAccount.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; contract SemiModularAccount7702 is SemiModularAccount { + error UpgradeNotAllowed(); + constructor(IEntryPoint anEntryPoint) SemiModularAccount(anEntryPoint) {} /// @inheritdoc IModularAccount @@ -13,6 +15,11 @@ contract SemiModularAccount7702 is SemiModularAccount { return "erc6900.reference-semi-modular-account-7702.0.8.0"; } + /// @dev To prevent accidental self-calls, upgrades are disabled in 7702 accounts. + function upgradeToAndCall(address, bytes memory) public payable override { + revert UpgradeNotAllowed(); + } + /// @dev If the fallback signer is set in storage, ignore the 7702 signer. function _retrieveFallbackSignerUnchecked(SemiModularAccountStorage storage _storage) internal