Skip to content

Commit c92d65b

Browse files
committed
refactor: move FunctionReference to IPluginManager
1 parent d6253cd commit c92d65b

File tree

8 files changed

+51
-50
lines changed

8 files changed

+51
-50
lines changed

src/account/AccountLoupe.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeab
55
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
66
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
77

8-
import {AccountStorage, getAccountStorage, HookGroup, toFunctionReferenceArray} from "./AccountStorage.sol";
9-
import {FunctionReference} from "../helpers/FunctionReferenceLib.sol";
108
import {IAccountLoupe} from "../interfaces/IAccountLoupe.sol";
11-
import {IPluginManager} from "../interfaces/IPluginManager.sol";
9+
import {FunctionReference, IPluginManager} from "../interfaces/IPluginManager.sol";
1210
import {IStandardExecutor} from "../interfaces/IStandardExecutor.sol";
11+
import {AccountStorage, getAccountStorage, HookGroup, toFunctionReferenceArray} from "./AccountStorage.sol";
1312

1413
abstract contract AccountLoupe is IAccountLoupe {
1514
using EnumerableMap for EnumerableMap.Bytes32ToUintMap;

src/account/AccountStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pragma solidity ^0.8.19;
44
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
55
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
66

7-
import {FunctionReference} from "../helpers/FunctionReferenceLib.sol";
87
import {IPlugin} from "../interfaces/IPlugin.sol";
8+
import {FunctionReference} from "../interfaces/IPluginManager.sol";
99

1010
// bytes = keccak256("ERC6900.UpgradeableModularAccount.Storage")
1111
bytes32 constant _ACCOUNT_STORAGE_SLOT = 0x9f09680beaa4e5c9f38841db2460c401499164f368baef687948c315d9073e40;

src/account/PluginManagerInternals.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.19;
33

4+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
45
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
56
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
6-
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
77

8-
import {
9-
AccountStorage,
10-
getAccountStorage,
11-
SelectorData,
12-
getPermittedCallKey,
13-
HookGroup,
14-
PermittedExternalCallData
15-
} from "./AccountStorage.sol";
16-
import {FunctionReference, FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
17-
import {IPluginManager} from "../interfaces/IPluginManager.sol";
8+
import {FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
189
import {
1910
IPlugin,
2011
ManifestExecutionHook,
@@ -24,10 +15,20 @@ import {
2415
ManifestExternalCallPermission,
2516
PluginManifest
2617
} from "../interfaces/IPlugin.sol";
18+
import {FunctionReference, IPluginManager} from "../interfaces/IPluginManager.sol";
19+
import {
20+
AccountStorage,
21+
getAccountStorage,
22+
SelectorData,
23+
getPermittedCallKey,
24+
HookGroup,
25+
PermittedExternalCallData
26+
} from "./AccountStorage.sol";
2727

2828
abstract contract PluginManagerInternals is IPluginManager {
2929
using EnumerableMap for EnumerableMap.Bytes32ToUintMap;
3030
using EnumerableSet for EnumerableSet.AddressSet;
31+
using FunctionReferenceLib for FunctionReference;
3132

3233
error ArrayLengthMismatch();
3334
error ExecutionFunctionAlreadySet(bytes4 selector);

src/account/UpgradeableModularAccount.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
pragma solidity ^0.8.19;
33

44
import {BaseAccount} from "@eth-infinitism/account-abstraction/core/BaseAccount.sol";
5-
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
6-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
75
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
8-
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
96
import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
107
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
8+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
9+
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
10+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
1111

12+
import {FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
13+
import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationDataHelpers.sol";
14+
import {IPlugin, PluginManifest} from "../interfaces/IPlugin.sol";
15+
import {IPluginExecutor} from "../interfaces/IPluginExecutor.sol";
16+
import {FunctionReference, IPluginManager} from "../interfaces/IPluginManager.sol";
17+
import {IStandardExecutor, Call} from "../interfaces/IStandardExecutor.sol";
1218
import {AccountExecutor} from "./AccountExecutor.sol";
1319
import {AccountLoupe} from "./AccountLoupe.sol";
1420
import {AccountStorage, HookGroup, getAccountStorage, getPermittedCallKey} from "./AccountStorage.sol";
1521
import {AccountStorageInitializable} from "./AccountStorageInitializable.sol";
16-
import {FunctionReference, FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
17-
import {IPlugin, PluginManifest} from "../interfaces/IPlugin.sol";
18-
import {IPluginExecutor} from "../interfaces/IPluginExecutor.sol";
19-
import {IPluginManager} from "../interfaces/IPluginManager.sol";
20-
import {IStandardExecutor, Call} from "../interfaces/IStandardExecutor.sol";
2122
import {PluginManagerInternals} from "./PluginManagerInternals.sol";
22-
import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationDataHelpers.sol";
2323

2424
contract UpgradeableModularAccount is
2525
AccountExecutor,
@@ -34,6 +34,7 @@ contract UpgradeableModularAccount is
3434
{
3535
using EnumerableMap for EnumerableMap.Bytes32ToUintMap;
3636
using EnumerableSet for EnumerableSet.Bytes32Set;
37+
using FunctionReferenceLib for FunctionReference;
3738

3839
struct PostExecToRun {
3940
bytes preExecHookReturnData;
@@ -437,7 +438,7 @@ contract UpgradeableModularAccount is
437438
++i;
438439
}
439440
} else {
440-
if (preRuntimeValidationHook == FunctionReferenceLib._PRE_HOOK_ALWAYS_DENY) {
441+
if (preRuntimeValidationHook.eq(FunctionReferenceLib._PRE_HOOK_ALWAYS_DENY)) {
441442
revert AlwaysDenyRule();
442443
}
443444
// Function reference cannot be 0 or _RUNTIME_VALIDATION_ALWAYS_ALLOW.
@@ -457,7 +458,7 @@ contract UpgradeableModularAccount is
457458
} else {
458459
if (runtimeValidationFunction.isEmpty()) {
459460
revert RuntimeValidationFunctionMissing(msg.sig);
460-
} else if (runtimeValidationFunction == FunctionReferenceLib._PRE_HOOK_ALWAYS_DENY) {
461+
} else if (runtimeValidationFunction.eq(FunctionReferenceLib._PRE_HOOK_ALWAYS_DENY)) {
461462
revert InvalidConfiguration();
462463
}
463464
// If _RUNTIME_VALIDATION_ALWAYS_ALLOW, just let the function finish.

src/helpers/FunctionReferenceLib.sol

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.19;
33

4-
type FunctionReference is bytes21;
5-
6-
using {eq as ==, notEq as !=} for FunctionReference global;
7-
using FunctionReferenceLib for FunctionReference global;
4+
import {FunctionReference} from "../interfaces/IPluginManager.sol";
85

96
library FunctionReferenceLib {
107
// Empty or unset function reference.
@@ -26,18 +23,18 @@ library FunctionReferenceLib {
2623
}
2724

2825
function isEmpty(FunctionReference fr) internal pure returns (bool) {
29-
return fr == _EMPTY_FUNCTION_REFERENCE;
26+
return FunctionReference.unwrap(fr) == bytes21(0);
3027
}
3128

3229
function isEmptyOrMagicValue(FunctionReference fr) internal pure returns (bool) {
3330
return FunctionReference.unwrap(fr) <= bytes21(uint168(2));
3431
}
35-
}
3632

37-
function eq(FunctionReference a, FunctionReference b) pure returns (bool) {
38-
return FunctionReference.unwrap(a) == FunctionReference.unwrap(b);
39-
}
33+
function eq(FunctionReference a, FunctionReference b) internal pure returns (bool) {
34+
return FunctionReference.unwrap(a) == FunctionReference.unwrap(b);
35+
}
4036

41-
function notEq(FunctionReference a, FunctionReference b) pure returns (bool) {
42-
return FunctionReference.unwrap(a) != FunctionReference.unwrap(b);
37+
function notEq(FunctionReference a, FunctionReference b) internal pure returns (bool) {
38+
return FunctionReference.unwrap(a) != FunctionReference.unwrap(b);
39+
}
4340
}

src/interfaces/IAccountLoupe.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: CC0-1.0
22
pragma solidity ^0.8.19;
33

4-
import {FunctionReference} from "../helpers/FunctionReferenceLib.sol";
4+
import {FunctionReference} from "../interfaces/IPluginManager.sol";
55

66
interface IAccountLoupe {
77
/// @notice Config for an execution function, given a selector.

src/interfaces/IPluginManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: CC0-1.0
22
pragma solidity ^0.8.19;
33

4-
import {FunctionReference} from "../helpers/FunctionReferenceLib.sol";
4+
type FunctionReference is bytes21;
55

66
interface IPluginManager {
77
event PluginInstalled(address indexed plugin, bytes32 manifestHash, FunctionReference[] dependencies);

test/libraries/FunctionReferenceLib.t.sol

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ pragma solidity ^0.8.19;
33

44
import {Test} from "forge-std/Test.sol";
55

6-
import {FunctionReference, FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol";
6+
import {FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol";
7+
import {FunctionReference} from "../../src/interfaces/IPluginManager.sol";
78

89
contract FunctionReferenceLibTest is Test {
10+
using FunctionReferenceLib for FunctionReference;
11+
912
function testFuzz_functionReference_packing(address addr, uint8 functionId) public {
1013
// console.log("addr: ", addr);
1114
// console.log("functionId: ", vm.toString(functionId));
@@ -19,19 +22,19 @@ contract FunctionReferenceLibTest is Test {
1922
}
2023

2124
function testFuzz_functionReference_operators(FunctionReference a, FunctionReference b) public {
22-
assertTrue(a == a);
23-
assertTrue(b == b);
25+
assertTrue(a.eq(a));
26+
assertTrue(b.eq(b));
2427

2528
if (FunctionReference.unwrap(a) == FunctionReference.unwrap(b)) {
26-
assertTrue(a == b);
27-
assertTrue(b == a);
28-
assertFalse(a != b);
29-
assertFalse(b != a);
29+
assertTrue(a.eq(b));
30+
assertTrue(b.eq(a));
31+
assertFalse(a.notEq(b));
32+
assertFalse(b.notEq(a));
3033
} else {
31-
assertTrue(a != b);
32-
assertTrue(b != a);
33-
assertFalse(a == b);
34-
assertFalse(b == a);
34+
assertTrue(a.notEq(b));
35+
assertTrue(b.notEq(a));
36+
assertFalse(a.eq(b));
37+
assertFalse(b.eq(a));
3538
}
3639
}
3740
}

0 commit comments

Comments
 (0)