Skip to content

Commit bff3964

Browse files
committed
refactor: use bool instead of struct to store permitted calls
1 parent c804a93 commit bff3964

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

src/account/AccountStorage.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ struct PluginData {
2121
uint256 dependentCount;
2222
}
2323

24-
// Represents data associated with a plugin's permission to use `executeFromPlugin`
25-
// to interact with another plugin installed on the account.
26-
struct PermittedCallData {
27-
bool callPermitted;
28-
}
29-
3024
// Represents data associated with a plugin's permission to use `executeFromPluginExternal`
3125
// to interact with contracts and addresses external to the account and its plugins.
3226
struct PermittedExternalCallData {
@@ -69,7 +63,7 @@ struct AccountStorage {
6963
// Execution functions and their associated functions
7064
mapping(bytes4 => SelectorData) selectorData;
7165
// bytes24 key = address(calling plugin) || bytes4(selector of execution function)
72-
mapping(bytes24 => PermittedCallData) permittedCalls;
66+
mapping(bytes24 => bool) callPermitted;
7367
// key = address(calling plugin) || target address
7468
mapping(IPlugin => mapping(address => PermittedExternalCallData)) permittedExternalCalls;
7569
// For ERC165 introspection

src/account/PluginManagerInternals.sol

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ abstract contract PluginManagerInternals is IPluginManager {
136136
_removeHooks(_selectorData.executionHooks, preExecHook, postExecHook);
137137
}
138138

139-
function _enableExecFromPlugin(bytes4 selector, address plugin, AccountStorage storage accountStorage)
140-
internal
141-
{
142-
bytes24 key = getPermittedCallKey(plugin, selector);
143-
144-
// If there are duplicates, this will just enable the flag again. This is not a problem, since the boolean
145-
// will be set to false twice during uninstall, which is fine.
146-
accountStorage.permittedCalls[key].callPermitted = true;
147-
}
148-
149-
function _disableExecFromPlugin(bytes4 selector, address plugin, AccountStorage storage accountStorage)
150-
internal
151-
{
152-
bytes24 key = getPermittedCallKey(plugin, selector);
153-
accountStorage.permittedCalls[key].callPermitted = false;
154-
}
155-
156139
function _addHooks(HookGroup storage hooks, FunctionReference preExecHook, FunctionReference postExecHook)
157140
internal
158141
{
@@ -306,7 +289,9 @@ abstract contract PluginManagerInternals is IPluginManager {
306289
// Add installed plugin and selectors this plugin can call
307290
length = manifest.permittedExecutionSelectors.length;
308291
for (uint256 i = 0; i < length;) {
309-
_enableExecFromPlugin(manifest.permittedExecutionSelectors[i], plugin, _storage);
292+
// If there are duplicates, this will just enable the flag again. This is not a problem, since the
293+
// boolean will be set to false twice during uninstall, which is fine.
294+
_storage.callPermitted[getPermittedCallKey(plugin, manifest.permittedExecutionSelectors[i])] = true;
310295

311296
unchecked {
312297
++i;
@@ -619,7 +604,7 @@ abstract contract PluginManagerInternals is IPluginManager {
619604

620605
length = manifest.permittedExecutionSelectors.length;
621606
for (uint256 i = 0; i < length;) {
622-
_disableExecFromPlugin(manifest.permittedExecutionSelectors[i], plugin, _storage);
607+
_storage.callPermitted[getPermittedCallKey(plugin, manifest.permittedExecutionSelectors[i])] = false;
623608

624609
unchecked {
625610
++i;

src/account/UpgradeableModularAccount.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ contract UpgradeableModularAccount is
183183

184184
AccountStorage storage _storage = getAccountStorage();
185185

186-
if (!_storage.permittedCalls[execFromPluginKey].callPermitted) {
186+
if (!_storage.callPermitted[execFromPluginKey]) {
187187
revert ExecFromPluginNotPermitted(callingPlugin, selector);
188188
}
189189

0 commit comments

Comments
 (0)