Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if plugin supports expected interface Id when enabling #74

Merged
merged 55 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f7aadcf
[#46] Implement Guard interface in SafeProtocolManager
akshay-ap Jul 26, 2023
175d0b9
[#47] Create FunctionHandlerManager.sol and inherit in SafeProtocolMa…
akshay-ap Jul 27, 2023
ef92c98
[#47] Create BaseManager contract, rename modifier, rename error, che…
akshay-ap Jul 27, 2023
5a52eef
[#47] Update natspec doc
akshay-ap Jul 27, 2023
2d4a1a1
Merge branch 'main' of github.com:5afe/safe-protocol into feature-46-…
akshay-ap Aug 2, 2023
1692fe0
[#46] Setup Safe
akshay-ap Aug 2, 2023
579ef82
Merge branch 'main' of github.com:5afe/safe-protocol into feature-46-…
akshay-ap Aug 2, 2023
1d73328
[#46] Fix EOF
akshay-ap Aug 2, 2023
89fba60
[#46] User setupTest function
akshay-ap Aug 2, 2023
6beead3
[#46] Fix lint issue
akshay-ap Aug 2, 2023
4ceb3e3
[#46] Add tests
akshay-ap Aug 2, 2023
69ed0db
[#46] Add test with delegateCall for hooks flow
akshay-ap Aug 3, 2023
3c2e2d6
[#46] User temporary variable for storing hooks address
akshay-ap Aug 3, 2023
6624509
Merge branch 'feature-46-hooks-for-multisig-flow' of github.com:5afe/…
akshay-ap Aug 6, 2023
69e227c
[#47] Implement logic for non-static calls to function handler manage…
akshay-ap Aug 6, 2023
8bf6053
[#47] Add tests for Function Handler
akshay-ap Aug 7, 2023
446084d
Merge branch 'main' of github.com:5afe/safe-protocol into feature-47-…
akshay-ap Aug 7, 2023
4a05518
[#47] Pass sender address in handle function
akshay-ap Aug 7, 2023
77d0b54
[#47] Fix test
akshay-ap Aug 9, 2023
b406518
[#47] Use ZeroAddress from ethers
akshay-ap Aug 9, 2023
55ef824
[#46] Reset tempHooksAddress
akshay-ap Aug 9, 2023
675fe12
[#47] Test static call to function handler
akshay-ap Aug 9, 2023
0af2503
[#47] Fix lint issue
akshay-ap Aug 9, 2023
6e98d70
Merge branch 'feature-46-hooks-for-multisig-flow' of github.com:5afe/…
akshay-ap Aug 9, 2023
842c2ad
[#47] Fix typo
akshay-ap Aug 9, 2023
f826f98
[#46] Refactor tests for SafeProtocolManager as Guard
akshay-ap Aug 14, 2023
6eb0388
Merge branch 'main' of github.com:5afe/safe-protocol into feature-46-…
akshay-ap Aug 14, 2023
98c24cc
[#46] Fix failing test
akshay-ap Aug 14, 2023
08ee3de
Merge branch 'feature-46-hooks-for-multisig-flow' of github.com:5afe/…
akshay-ap Aug 15, 2023
dc14c0d
[#46] Update comment
akshay-ap Aug 15, 2023
dda6733
Merge branch 'feature-46-hooks-for-multisig-flow' of github.com:5afe/…
akshay-ap Aug 15, 2023
cc7513c
[#47] Update tests for Function Handler
akshay-ap Aug 15, 2023
1d749ec
[#47] Update tests for function handler
akshay-ap Aug 15, 2023
68705f1
[#47] Remove test function handler from .solcover.js
akshay-ap Aug 15, 2023
eecbd26
[#47] Return data from handle function
akshay-ap Aug 15, 2023
4029549
[#47] Verify call data passed to handle(...)
akshay-ap Aug 15, 2023
707d39e
[#47] Update doc string
akshay-ap Aug 16, 2023
c262612
[#47] Check if function handler is whitelisted
akshay-ap Aug 16, 2023
28d5645
[#47] Make fallback function non-payable, optimize codesize
akshay-ap Aug 16, 2023
9400aef
[#47] Fix lint issue
akshay-ap Aug 16, 2023
11ce14f
[#47] Add ERC165 check while adding function handler
akshay-ap Aug 17, 2023
180fb38
Merge branch 'main' of github.com:5afe/safe-protocol into feature-47-…
akshay-ap Aug 17, 2023
7a5e830
Merge branch 'main' of github.com:5afe/safe-protocol into feature-47-…
akshay-ap Aug 17, 2023
f48c12d
[#47] Allow only self calls to manager
akshay-ap Aug 20, 2023
8319bfd
[#47] Add tests for function handler
akshay-ap Aug 20, 2023
5d6abf4
[#47] Add tests
akshay-ap Aug 21, 2023
754da7d
[#47] Rename function to `checkCallerisSender()`
akshay-ap Aug 21, 2023
e2d5eec
[#47] Rename to OnlyAccountCallable, add docstrings
akshay-ap Aug 21, 2023
1561278
[#47] Update string in describe
akshay-ap Aug 21, 2023
7acc9cc
[#47] Update natspec doc for RegistryManager constructor
akshay-ap Aug 21, 2023
e3c71ef
[#47] Update natspec doc for FunctionHandlerManager
akshay-ap Aug 21, 2023
52ae52f
[#73] Check if plugin supports expected interface Id when enabling
akshay-ap Aug 21, 2023
9c624c1
Merge branch 'main' of github.com:5afe/safe-protocol into feature-73-…
akshay-ap Aug 22, 2023
c9b8c80
[#73] Fix lint issue
akshay-ap Aug 22, 2023
f44918a
[#73] Add test for Manager: block EOA as Plugin
akshay-ap Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/SafeProtocolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ contract SafeProtocolManager is ISafeProtocolManager, RegistryManager, HooksMana
address plugin,
bool allowRootAccess
) external noZeroOrSentinelPlugin(plugin) onlyPermittedIntegration(plugin) onlyAccount {
// address(0) check omitted because it is not expected to enable it as a plugin and
// call to it would fail. Additionally, registry should not permit address(0) as an integration.
if (!ISafeProtocolPlugin(plugin).supportsInterface(type(ISafeProtocolPlugin).interfaceId))
revert AccountDoesNotImplementValidInterfaceId(plugin);

PluginAccessInfo storage senderSentinelPlugin = enabledPlugins[msg.sender][SENTINEL_MODULES];
PluginAccessInfo storage senderPlugin = enabledPlugins[msg.sender][plugin];

Expand Down
33 changes: 33 additions & 0 deletions test/SafeProtocolManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ describe("SafeProtocolManager", async () => {
.withArgs(pluginAddress, 0, 0);
});

it("Should not allow a Safe to enable plugin that does not support ERC165", async () => {
akshay-ap marked this conversation as resolved.
Show resolved Hide resolved
const { safeProtocolManager, safe, safeProtocolRegistry } = await loadFixture(deployContractsWithPluginFixture);
await safe.setModule(await safeProtocolManager.getAddress());

const mockPlugin = await hre.ethers.deployContract("MockContract");
await mockPlugin.givenMethodReturnBool("0x01ffc9a7", true);
await safeProtocolRegistry.connect(owner).addIntegration(mockPlugin.target, IntegrationType.Plugin);

await mockPlugin.givenMethodReturnBool("0x01ffc9a7", false);
const data = safeProtocolManager.interface.encodeFunctionData("enablePlugin", [mockPlugin.target, false]);
await expect(safe.exec(safe.target, 0, data))
.to.be.revertedWithCustomError(safeProtocolManager, "AccountDoesNotImplementValidInterfaceId")
.withArgs(mockPlugin.target);
});

it("Should not allow a Safe to enable plugin having no code", async () => {
// This test simulates case when a Plugin is added in registry but later has no code
// because it calls selfdestruct.

// Setup mock registry. Required to bypass ERC165 checks for user2.address as it is an EOA.
const safeProtocolRegistry = await hre.ethers.deployContract("MockContract");
await safeProtocolRegistry.givenMethodReturnBool("0x01ffc9a7", true);

const safeProtocolManager = await (
await hre.ethers.getContractFactory("SafeProtocolManager")
).deploy(owner.address, await safeProtocolRegistry.getAddress());
akshay-ap marked this conversation as resolved.
Show resolved Hide resolved

const safe = await hre.ethers.deployContract("TestExecutor", [safeProtocolManager.target], { signer: deployer });
const data = safeProtocolManager.interface.encodeFunctionData("enablePlugin", [user2.address, false]);

await expect(safe.exec(safe.target, 0, data)).to.be.reverted;
});

it("Should not allow a Safe to enable plugin if flagged in registry", async () => {
const { safeProtocolManager, safe, plugin, safeProtocolRegistry } = await loadFixture(deployContractsWithPluginFixture);
await safe.setModule(await safeProtocolManager.getAddress());
Expand Down