Skip to content

Commit 3bf8109

Browse files
fix: STAA-12 remediation commit iv
1 parent 7f7cebd commit 3bf8109

File tree

5 files changed

+15
-54
lines changed

5 files changed

+15
-54
lines changed

src/StartaleSmartAccount.sol

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
pragma solidity ^0.8.29;
33

44
import {BaseAccount} from './core/BaseAccount.sol';
5-
65
import {ERC7779Adapter} from './core/ERC7779Adapter.sol';
76
import {ExecutionHelper} from './core/ExecutionHelper.sol';
87
import {ModuleManager} from './core/ModuleManager.sol';
9-
108
import {IERC7579Account} from './interfaces/IERC7579Account.sol';
119
import {IValidator} from './interfaces/IERC7579Module.sol';
1210
import {IStartaleSmartAccount} from './interfaces/IStartaleSmartAccount.sol';
1311
import {IAccountConfig} from './interfaces/core/IAccountConfig.sol';
1412
import {ExecutionLib} from './lib/ExecutionLib.sol';
15-
import {ACCOUNT_STORAGE_LOCATION} from './types/Constants.sol';
16-
import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol';
17-
import {IERC1155Receiver} from '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol';
18-
import {IERC721Receiver} from '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
19-
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
2013

2114
import {Initializable} from './lib/Initializable.sol';
2215
import {
@@ -31,6 +24,7 @@ import {
3124
ModeLib
3225
} from './lib/ModeLib.sol';
3326
import {NonceLib} from './lib/NonceLib.sol';
27+
import {ACCOUNT_STORAGE_LOCATION} from './types/Constants.sol';
3428
import {
3529
MODULE_TYPE_EXECUTOR,
3630
MODULE_TYPE_FALLBACK,
@@ -43,11 +37,13 @@ import {
4337
VALIDATION_FAILED,
4438
VALIDATION_SUCCESS
4539
} from './types/Constants.sol';
46-
4740
import {EmergencyUninstall} from './types/Structs.sol';
48-
4941
import {_packValidationData} from '@account-abstraction/core/Helpers.sol';
5042
import {PackedUserOperation} from '@account-abstraction/interfaces/PackedUserOperation.sol';
43+
import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol';
44+
import {IERC1155Receiver} from '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol';
45+
import {IERC721Receiver} from '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
46+
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
5147
import {SENTINEL, SentinelListLib, ZERO_ADDRESS} from 'sentinellist/SentinelList.sol';
5248
import {UUPSUpgradeable} from 'solady/utils/UUPSUpgradeable.sol';
5349

@@ -338,11 +334,10 @@ contract StartaleSmartAccount is
338334
/// @dev Uninstalls all validators, executors, hooks, and pre-validation hooks.
339335
/// @notice It is worth noting that, onRedelegation() does not obligate the account to completely wipe out it’s storage.
340336
/// @notice It is an optional action for the account where it could uninitialize the storage variables as much as it can to provide clean storage for new wallet.
341-
/// Review: _onRedelegation. If ERC authors agrees with the change then we could have bytes calldata context as param.
342337
function _onRedelegation() internal override {
343-
_tryUninstallValidators();
344-
_tryUninstallExecutors();
345-
_tryUninstallHook(_getHook());
338+
_uninstallAllValidators();
339+
_uninstallAllExecutors();
340+
_uninstallHook(_getHook());
346341
_tryUninstallPreValidationHook(
347342
_getPreValidationHook(MODULE_TYPE_PREVALIDATION_HOOK_ERC1271), MODULE_TYPE_PREVALIDATION_HOOK_ERC1271
348343
);

src/core/ModuleManager.sol

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,10 @@ abstract contract ModuleManager is AllStorage, EIP712, IModuleManager {
245245
}
246246
}
247247

248-
/// Review: _tryUninstallValidators Might as well not call onUninstall() at all
249-
/// Review: separate internal method can be added that accepts an array of data.
250248
/// @dev Uninstalls all validators from the smart account.
251249
/// @dev This function is called in the _onRedelegation function in StartaleSmartAccount.sol
252-
function _tryUninstallValidators() internal {
250+
function _uninstallAllValidators() internal {
253251
SentinelListLib.SentinelList storage $valdiators = _getAccountStorage().validators;
254-
address validator = $valdiators.getNext(SENTINEL);
255-
while (validator != SENTINEL) {
256-
try IValidator(validator).onUninstall('') {}
257-
catch {
258-
emit ValidatorUninstallFailed(validator, '');
259-
}
260-
validator = $valdiators.getNext(validator);
261-
}
262252
$valdiators.popAll();
263253
}
264254

@@ -289,20 +279,10 @@ abstract contract ModuleManager is AllStorage, EIP712, IModuleManager {
289279
}
290280
}
291281

292-
/// Review: _tryUninstallExecutors Might as well not call onUninstall() at all
293-
/// Review: separate internal method can be added that accepts an array of data.
294282
/// @dev Uninstalls all executors from the smart account.
295283
/// @dev This function is called in the _onRedelegation function in StartaleSmartAccount.sol
296-
function _tryUninstallExecutors() internal {
284+
function _uninstallAllExecutors() internal {
297285
SentinelListLib.SentinelList storage $executors = _getAccountStorage().executors;
298-
address executor = $executors.getNext(SENTINEL);
299-
while (executor != SENTINEL) {
300-
try IExecutor(executor).onUninstall('') {}
301-
catch {
302-
emit ExecutorUninstallFailed(executor, '');
303-
}
304-
executor = $executors.getNext(executor);
305-
}
306286
$executors.popAll();
307287
}
308288

@@ -337,20 +317,14 @@ abstract contract ModuleManager is AllStorage, EIP712, IModuleManager {
337317
}
338318
}
339319

340-
/// Review: _tryUninstallHook
341320
/// @dev Uninstalls a hook module.
342321
/// @param hook The address of the hook to be uninstalled.
343-
function _tryUninstallHook(address hook) internal virtual {
322+
function _uninstallHook(address hook) internal virtual {
344323
if (hook != address(0)) {
345-
try IHook(hook).onUninstall('') {}
346-
catch {
347-
emit HookUninstallFailed(hook, '');
348-
}
349324
_setHook(address(0));
350325
}
351326
}
352327

353-
// Review: if uninstalling selectors also need some data.
354328
function _tryUninstallFallbacks() internal {
355329
AccountStorage storage ds = _getAccountStorage();
356330
uint256 len = ds.fallbackSelectors.length;
@@ -556,14 +530,13 @@ abstract contract ModuleManager is AllStorage, EIP712, IModuleManager {
556530
uint256 hookType,
557531
bytes calldata data
558532
) internal virtual {
559-
// Review
560-
// Check if the hook is installed according to supplied type
561-
// Check if the hook is one of the allowed types
562-
// IModule(preValidationHook).onUninstall(data);
563533
_setPreValidationHook(hookType, address(0));
534+
try IModule(preValidationHook).onUninstall(data) {}
535+
catch {
536+
emit PreValidationHookUninstallFailed(preValidationHook, data);
537+
}
564538
}
565539

566-
// Review: _tryUninstallPreValidationHook
567540
function _tryUninstallPreValidationHook(address hook, uint256 hookType) internal virtual {
568541
if (hook == address(0)) return;
569542
if (hookType == MODULE_TYPE_PREVALIDATION_HOOK_ERC1271) {

src/modules/validators/ECDSAValidator.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ contract ECDSAValidator is IValidator, ERC7739Validator {
139139
* @param _newOwner The address of the new owner
140140
*/
141141
function transferOwnership(address _newOwner) external {
142-
// Review: other checks on newOwner address
143142
if (_newOwner == address(0)) {
144143
revert OwnerCannotBeZeroAddress();
145144
}

src/types/Constants.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ uint256 constant VALIDATION_SUCCESS = 0;
1313
// Value indicating failed validation
1414
uint256 constant VALIDATION_FAILED = 1;
1515

16-
// Review: Alternate naming
17-
// Todo: Maybe arrange constants in category of their context
18-
// uint256 constant SIG_VALIDATION_FAILED_UINT = 1;
19-
// uint256 constant SIG_VALIDATION_SUCCESS_UINT = 0;
20-
2116
// Module type identifier for Multitype install
2217
uint256 constant MODULE_TYPE_MULTI = 0;
2318

test/foundry/unit/concrete/execution/TestExecution_ExecuteFromExecutor.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ contract TestExecution_ExecuteFromExecutor is TestExecutionBase {
4747
}
4848

4949
/// @notice Tests delegate call execution via MockExecutor
50-
// Review
5150
function test_ExecuteDelegateCallFromExecutor_Success() public {
5251
(bool res,) = payable(address(BOB_ACCOUNT)).call{value: 2 ether}(''); // Fund BOB_ACCOUNT
5352
assertEq(res, true, 'Funding BOB_ACCOUNT should succeed');

0 commit comments

Comments
 (0)