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

⚰️ Removing console logs #82

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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: 2 additions & 0 deletions examples/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read", path = "out-optimized" }]
allow_paths = ["*", "/"]
evm_version = "cancun"
ignored_error_codes = [2394]

[fmt]
bracket_spacing = true
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
224 changes: 224 additions & 0 deletions examples/src/HookMultiplex/Base.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { ERC7579HookBase } from "@rhinestone/modulekit/src/modules/ERC7579HookBase.sol";
import { IERC7579Account } from "@rhinestone/modulekit/src/Accounts.sol";
import { ExecutionLib, Execution } from "erc7579/lib/ExecutionLib.sol";
import {
ModeLib,
CallType,
ModeCode,
CALLTYPE_SINGLE,
CALLTYPE_BATCH,
CALLTYPE_DELEGATECALL
} from "erc7579/lib/ModeLib.sol";

uint256 constant EXEC_OFFSET = 100;
uint256 constant INSTALL_OFFSET = 132;

abstract contract ERC7579HookDestruct is ERC7579HookBase {
error HookInvalidSelector();

/*//////////////////////////////////////////////////////////////////////////
CALLDATA DECODING
//////////////////////////////////////////////////////////////////////////*/

function preCheck(
address msgSender,
bytes calldata msgData
)
external
virtual
override
returns (bytes memory hookData)
{
bytes4 selector = bytes4(msgData[0:4]);

if (selector == IERC7579Account.execute.selector) {
return _handle4337Executions(msgSender, msgData);
} else if (selector == IERC7579Account.executeFromExecutor.selector) {
return _handleExecutorExecutions(msgSender, msgData);
} else if (selector == IERC7579Account.installModule.selector) {
uint256 paramLen = uint256(bytes32(msgData[INSTALL_OFFSET - 32:INSTALL_OFFSET]));
bytes calldata initData = msgData[INSTALL_OFFSET:INSTALL_OFFSET + paramLen];
uint256 moduleType = uint256(bytes32(msgData[4:36]));
address module = address(bytes20((msgData[48:68])));
return onInstallModule(msgSender, moduleType, module, initData);
} else if (selector == IERC7579Account.uninstallModule.selector) {
uint256 paramLen = uint256(bytes32(msgData[INSTALL_OFFSET - 32:INSTALL_OFFSET]));
bytes calldata initData = msgData[INSTALL_OFFSET:INSTALL_OFFSET + paramLen];
uint256 moduleType = uint256(bytes32(msgData[4:36]));
address module = address(bytes20((msgData[48:68])));

return onUninstallModule(msgSender, moduleType, module, initData);
} else {
revert();
}
}

function _handle4337Executions(
address msgSender,
bytes calldata msgData
)
internal
returns (bytes memory hookData)
{
uint256 paramLen = uint256(bytes32(msgData[EXEC_OFFSET - 32:EXEC_OFFSET]));
bytes calldata encodedExecutions = msgData[EXEC_OFFSET:EXEC_OFFSET + paramLen];

ModeCode mode = ModeCode.wrap(bytes32(msgData[4:36]));
CallType calltype = ModeLib.getCallType(mode);

if (calltype == CALLTYPE_SINGLE) {
(address to, uint256 value, bytes calldata callData) =
ExecutionLib.decodeSingle(encodedExecutions);
return onExecute(msgSender, to, value, callData);
} else if (calltype == CALLTYPE_BATCH) {
Execution[] calldata execs = ExecutionLib.decodeBatch(encodedExecutions);
return onExecuteBatch(msgSender, execs);
}
}

function _handleExecutorExecutions(
address msgSender,
bytes calldata msgData
)
internal
returns (bytes memory hookData)
{
uint256 paramLen = uint256(bytes32(msgData[EXEC_OFFSET - 32:EXEC_OFFSET]));
bytes calldata encodedExecutions = msgData[EXEC_OFFSET:EXEC_OFFSET + paramLen];

ModeCode mode = ModeCode.wrap(bytes32(msgData[4:36]));
CallType calltype = ModeLib.getCallType(mode);

if (calltype == CALLTYPE_SINGLE) {
(address to, uint256 value, bytes calldata callData) =
ExecutionLib.decodeSingle(encodedExecutions);
return onExecuteFromExecutor(msgSender, to, value, callData);
} else if (calltype == CALLTYPE_BATCH) {
Execution[] calldata execs = ExecutionLib.decodeBatch(encodedExecutions);
return onExecuteBatchFromExecutor(msgSender, execs);
}
}

// if (selector == IERC7579Account.execute.selector) {
// ModeCode mode = ModeCode.wrap(bytes32(msgData[4:36]));
// CallType calltype = ModeLib.getCallType(mode);
// uint256 offset = msgData.offset();
// if (calltype == CALLTYPE_SINGLE) {
// (address to, uint256 value, bytes calldata callData) =
// ExecutionLib.decodeSingle(msgData[36:offset]);
// return onExecute(msgSender, to, value, callData);
// } else if (calltype == CALLTYPE_BATCH) {
// Execution[] calldata execs = ExecutionLib.decodeBatch(msgData[36:offset]);
// return onExecuteBatch(msgSender, execs);
// } else {
// revert HookInvalidSelector();
// }
// } else if (selector == IERC7579Account.executeFromExecutor.selector) {
// uint256 offset = msgData.offset();
//
// ModeCode mode = ModeCode.wrap(bytes32(msgData[4:36]));
// CallType calltype = ModeLib.getCallType(mode);
// if (calltype == CALLTYPE_SINGLE) {
// (address to, uint256 value, bytes calldata callData) =
// ExecutionLib.decodeSingle(msgData[36:offset]);
// return onExecuteFromExecutor(msgSender, to, value, callData);
// } else if (calltype == CALLTYPE_BATCH) {
// Execution[] calldata execs = ExecutionLib.decodeBatch(msgData[36:offset]);
// return onExecuteBatchFromExecutor(msgSender, execs);
// } else {
// revert HookInvalidSelector();
// }
// } else if (selector == IERC7579Account.installModule.selector) {
// uint256 offset = msgData.offset();
// uint256 moduleType = uint256(bytes32(msgData[4:24]));
// address module = address(bytes20(msgData[24:36]));
// bytes calldata initData = msgData[36:offset];
// onInstallModule(msgSender, moduleType, module, initData);
// } else if (selector == IERC7579Account.uninstallModule.selector) {
// uint256 offset = msgData.offset();
// uint256 moduleType = uint256(bytes32(msgData[4:24]));
// address module = address(bytes20(msgData[24:36]));
// bytes calldata initData = msgData[36:offset];
// onUninstallModule(msgSender, moduleType, module, initData);
// } else {
// revert HookInvalidSelector();
// }

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

/*//////////////////////////////////////////////////////////////////////////
EXECUTION
//////////////////////////////////////////////////////////////////////////*/

function onExecute(
address msgSender,
address target,
uint256 value,
bytes calldata callData
)
internal
virtual
returns (bytes memory hookData);

function onExecuteBatch(
address msgSender,
Execution[] calldata
)
internal
virtual
returns (bytes memory hookData);

function onExecuteFromExecutor(
address msgSender,
address target,
uint256 value,
bytes calldata callData
)
internal
virtual
returns (bytes memory hookData);

function onExecuteBatchFromExecutor(
address msgSender,
Execution[] calldata
)
internal
virtual
returns (bytes memory hookData);

/*//////////////////////////////////////////////////////////////////////////
CONFIG
//////////////////////////////////////////////////////////////////////////*/

function onInstallModule(
address msgSender,
uint256 moduleType,
address module,
bytes calldata initData
)
internal
virtual
returns (bytes memory hookData);

function onUninstallModule(
address msgSender,
uint256 moduleType,
address module,
bytes calldata deInitData
)
internal
virtual
returns (bytes memory hookData);

/*//////////////////////////////////////////////////////////////////////////
POSTCHECK
//////////////////////////////////////////////////////////////////////////*/

function onPostCheck(bytes calldata hookData) internal virtual returns (bool success);
}
Loading
Loading