Skip to content

Commit

Permalink
prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 26, 2024
1 parent 3ed365d commit 0696009
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 37 deletions.
2 changes: 1 addition & 1 deletion accounts/safe7579/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@prb/math": "^4.0.2",
"forge-std": "github:foundry-rs/forge-std",
"ds-test": "github:dapphub/ds-test",
"erc7579": "github:erc7579/erc7579-implementation",
"erc7579": "github:erc7579/erc7579-implementation#feature/hookRevert",
"sentinellist": "github:zeroknots/sentinellist",
"solady": "github:vectorized/solady",
"solarray": "github:sablier-labs/solarray",
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0",
"forge-std": "github:foundry-rs/forge-std",
"ds-test": "github:dapphub/ds-test",
"erc7579": "github:erc7579/erc7579-implementation",
"erc7579": "github:erc7579/erc7579-implementation#feature/hookRevert",
"sentinellist": "github:zeroknots/sentinellist",
"solady": "github:vectorized/solady",
"solarray": "github:sablier-labs/solarray",
Expand Down
4 changes: 1 addition & 3 deletions examples/src/DeadmanSwitch/DeadmanSwitch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ contract DeadmanSwitch is ERC7579HookBase, ERC7579ValidatorBase {
config.lastAccess = uint48(block.timestamp);
}

function postCheck(bytes calldata) external pure returns (bool success) {
success = true;
}
function postCheck(bytes calldata) external { }

function validateUserOp(
PackedUserOperation calldata userOp,
Expand Down
15 changes: 10 additions & 5 deletions examples/src/PermissionsHook/PermissionsHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Execution, IERC7579Account } from "@rhinestone/modulekit/src/Accounts.s
import { IERC721 } from "forge-std/interfaces/IERC721.sol";
import { IERC20 } from "forge-std/interfaces/IERC20.sol";

import "forge-std/console2.sol";

contract PermissionsHook is ERC7579HookDestruct {
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
Expand Down Expand Up @@ -114,6 +116,9 @@ contract PermissionsHook is ERC7579HookDestruct {
returns (bytes memory hookData)
{
// Not callable from module
ModulePermissions memory modulePermissions = permissions[msg.sender][msgSender];
console2.log("modulePermissions", modulePermissions.moduleCall);
_validateExecutePermissions(modulePermissions, target, value, callData);
}

function onExecuteBatch(
Expand Down Expand Up @@ -231,11 +236,11 @@ contract PermissionsHook is ERC7579HookDestruct {
revert InvalidPermission();
}

if (!modulePermissions.moduleCall) {
if (IERC7579Account(msg.sender).isModuleInstalled(TYPE_EXECUTOR, target, "")) {
revert InvalidPermission();
}
}
// if (!modulePermissions.moduleCall) {
// if (IERC7579Account(msg.sender).isModuleInstalled(TYPE_EXECUTOR, target, "")) {
// revert InvalidPermission();
// }
// }

if (modulePermissions.hasAllowedTargets) {
bool isAllowedTarget = false;
Expand Down
1 change: 1 addition & 0 deletions examples/test/MultiFactor/MultiFactor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "forge-std/Test.sol";
import "@rhinestone/modulekit/src/ModuleKit.sol";
import "@rhinestone/modulekit/src/Modules.sol";
import "@rhinestone/modulekit/src/Mocks.sol";
import { EncodedModuleTypes } from "erc7579/lib/ModuleTypeLib.sol";

import { MultiFactor, ECDSAFactor } from "src/MultiFactor/MultiFactor.sol";
import { SignatureCheckerLib } from "solady/src/utils/SignatureCheckerLib.sol";
Expand Down
37 changes: 32 additions & 5 deletions examples/test/PermissionsHook/PermissionsHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract PermissionsHookTest is RhinestoneModuleKit, Test {
}

function setUpPermissionsHook() internal {
console2.log("setting up permissions hook");
instance.installModule({
moduleTypeId: MODULE_TYPE_EXECUTOR,
module: address(executorDisallowed),
Expand All @@ -58,12 +59,13 @@ contract PermissionsHookTest is RhinestoneModuleKit, Test {
data: ""
});

address[] memory executors = new address[](2);
executors[0] = address(executorDisallowed);
executors[1] = address(executorAllowed);
address[] memory modules = new address[](3);
modules[0] = address(executorDisallowed);
modules[1] = address(executorAllowed);
modules[2] = address(instance.defaultValidator);

PermissionsHook.ModulePermissions[] memory permissions =
new PermissionsHook.ModulePermissions[](2);
new PermissionsHook.ModulePermissions[](3);
permissions[0] = PermissionsHook.ModulePermissions({
selfCall: false,
moduleCall: false,
Expand All @@ -90,11 +92,26 @@ contract PermissionsHookTest is RhinestoneModuleKit, Test {
allowedTargets: new address[](0)
});

permissions[2] = PermissionsHook.ModulePermissions({
selfCall: true,
moduleCall: true,
hasAllowedTargets: false,
sendValue: true,
hasAllowedFunctions: false,
erc20Transfer: true,
erc721Transfer: true,
moduleConfig: true,
allowedFunctions: new bytes4[](0),
allowedTargets: new address[](0)
});

console2.log("installing module");
instance.installModule({
moduleTypeId: MODULE_TYPE_HOOK,
module: address(permissionsHook),
data: abi.encode(executors, permissions)
data: abi.encode(modules, permissions)
});
console2.log("installed");
}

modifier performWithBothExecutors() {
Expand Down Expand Up @@ -138,4 +155,14 @@ contract PermissionsHookTest is RhinestoneModuleKit, Test {
(bool success, bytes memory result) = activeExecutor.call(executorCallData);
activeCallSuccess = success;
}

function test_sendValue_4337() public performWithBothExecutors {
address target = makeAddr("target");
uint256 balanceBefore = target.balance;
uint256 value = 1 ether;
bytes memory callData = "";

instance.exec({ target: address(target), value: value, callData: callData });
assertEq(target.balance, balanceBefore + value);
}
}
2 changes: 1 addition & 1 deletion packages/SessionKeyManager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@ERC4337/account-abstraction": "github:kopy-kat/account-abstraction#develop",
"@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0",
"sentinellist": "github:zeroknots/sentinellist",
"erc7579": "github:erc7579/erc7579-implementation",
"erc7579": "github:erc7579/erc7579-implementation#feature/hookRevert",
"forge-std": "github:foundry-rs/forge-std",
"solady": "github:vectorized/solady",
"solhint": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/modulekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@ERC4337/account-abstraction": "github:kopy-kat/account-abstraction#develop",
"@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0",
"@safe-global/safe-contracts": "^1.4.1",
"erc7579": "github:erc7579/erc7579-implementation",
"erc7579": "github:erc7579/erc7579-implementation#feature/hookRevert",
"prettier": "^2.8.8",
"sentinellist": "github:zeroknots/sentinellist",
"solady": "github:vectorized/solady",
Expand Down
4 changes: 1 addition & 3 deletions packages/modulekit/src/mocks/MockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ contract MockHook is ERC7579HookBase {
returns (bytes memory hookData)
{ }

function postCheck(bytes calldata) external virtual override returns (bool success) {
return true;
}
function postCheck(bytes calldata) external virtual override { }

function isInitialized(address smartAccount) external pure returns (bool) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions packages/modulekit/src/modules/ERC7579HookDestruct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ abstract contract ERC7579HookDestruct is ERC7579HookBase {
// revert HookInvalidSelector();
// }

function postCheck(bytes calldata hookData) external override returns (bool success) {
if (hookData.length == 0) return true;
return onPostCheck(hookData);
function postCheck(bytes calldata hookData) external override {
if (hookData.length == 0) return;
if (onPostCheck(hookData) == false) revert();
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
91 changes: 77 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0696009

Please sign in to comment.