Skip to content

Commit

Permalink
Merge pull request #11 from dodger213/temp2
Browse files Browse the repository at this point in the history
Temp2
  • Loading branch information
dodger213 authored Aug 18, 2024
2 parents 66d223e + 76a6a12 commit e90d07c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 7 deletions.
8 changes: 7 additions & 1 deletion contracts/SafeL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ contract SafeL2 is Safe {
* @inheritdoc ModuleManager
*/
function onBeforeExecTransactionFromModule(address to, uint256 value, bytes memory data, Enum.Operation operation) internal override {
function onBeforeExecTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes memory /* context */
) internal override {
emit SafeModuleTransaction(msg.sender, to, value, data, operation);

}
Expand Down
67 changes: 61 additions & 6 deletions contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface IModuleGuard is IERC165 {
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes memory context,
address module
) external returns (bytes32 moduleTxHash);

Expand Down Expand Up @@ -88,23 +89,25 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager {
* @param value Ether value of module transaction.
* @param data Data payload of module transaction.
* @param operation Operation type of module transaction.
* @param context Context of the module transaction.
* @return guard Guard to be used for checking.
* @return guardHash Hash returned from the guard tx check.
*/
function preModuleExecution(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
Enum.Operation operation,
bytes calldata context
) internal returns (address guard, bytes32 guardHash) {
onBeforeExecTransactionFromModule(to, value, data, operation);
onBeforeExecTransactionFromModule(to, value, data, operation, context);
guard = getModuleGuard();

// Only whitelisted modules are allowed.
require(msg.sender != SENTINEL_MODULES && modules[msg.sender] != address(0), "GS104");

if (guard != address(0)) {
guardHash = IModuleGuard(guard).checkModuleTransaction(to, value, data, operation, msg.sender);
guardHash = IModuleGuard(guard).checkModuleTransaction(to, value, data, operation, context, msg.sender);
}
}

Expand Down Expand Up @@ -148,6 +151,19 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager {
emit DisabledModule(module);
}

/**
* @inheritdoc IModuleManager
*/
function execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) external override returns (bool success) {
success = _execTransactionFromModule(to, value, data, operation, context);
}

/**
* @inheritdoc IModuleManager
*/
Expand All @@ -157,7 +173,17 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager {
bytes memory data,
Enum.Operation operation
) external override returns (bool success) {
(address guard, bytes32 guardHash) = preModuleExecution(to, value, data, operation);
success = _execTransactionFromModule(to, value, data, operation, "");
}

function _execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) internal returns (bool success) {
(address guard, bytes32 guardHash) = preModuleExecution(to, value, data, operation, context);
success = execute(to, value, data, operation, type(uint256).max);
postModuleExecution(guard, guardHash, success);

Expand All @@ -172,7 +198,30 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager {
bytes memory data,
Enum.Operation operation
) external override returns (bool success, bytes memory returnData) {
(address guard, bytes32 guardHash) = preModuleExecution(to, value, data, operation);
(success, returnData) = _execTransactionFromModuleReturnData(to, value, data, operation, "");
}

/**
* @inheritdoc IModuleManager
*/
function execTransactionFromModuleReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) external override returns (bool success, bytes memory returnData) {
(success, returnData) = _execTransactionFromModuleReturnData(to, value, data, operation, context);
}

function _execTransactionFromModuleReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) internal returns (bool success, bytes memory returnData) {
(address guard, bytes32 guardHash) = preModuleExecution(to, value, data, operation, context);
success = execute(to, value, data, operation, type(uint256).max);
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
Expand Down Expand Up @@ -288,5 +337,11 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager {
* @param data Data payload of module transaction.
* @param operation Operation type of module transaction.
*/
function onBeforeExecTransactionFromModule(address to, uint256 value, bytes memory data, Enum.Operation operation) internal virtual {}
function onBeforeExecTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) internal virtual {}
}
1 change: 1 addition & 0 deletions contracts/examples/guards/DebugTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ contract DebugTransactionGuard is BaseGuard {
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes memory /* context */,
address module
) external override returns (bytes32 moduleTxHash) {
moduleTxHash = keccak256(abi.encodePacked(to, value, data, operation, module));
Expand Down
1 change: 1 addition & 0 deletions contracts/examples/guards/DelegateCallTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ contract DelegateCallTransactionGuard is BaseGuard {
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes memory /* context */,
address module
) external view override returns (bytes32 moduleTxHash) {
require(operation != Enum.Operation.DelegateCall || to == ALLOWED_TARGET, "This call is restricted");
Expand Down
1 change: 1 addition & 0 deletions contracts/examples/guards/ReentrancyTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ contract ReentrancyTransactionGuard is BaseGuard {
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes memory /* context */,
address module
) external override returns (bytes32 moduleTxHash) {
moduleTxHash = keccak256(abi.encodePacked(to, value, data, operation, module));
Expand Down
36 changes: 36 additions & 0 deletions contracts/interfaces/IModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ interface IModuleManager {
Enum.Operation operation
) external returns (bool success);

/**
* @notice Execute `operation` (0: Call, 1: DelegateCall) to `to` with `value` (Native Token)
* @dev Function is virtual to allow overriding for L2 singleton to emit an event for indexing.
* @param to Destination address of module transaction.
* @param value Ether value of module transaction.
* @param data Data payload of module transaction.
* @param operation Operation type of module transaction.
* @param context Additional context information for the module transaction.
* @return success Boolean flag indicating if the call succeeded.
*/
function execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) external returns (bool success);

/**
* @notice Execute `operation` (0: Call, 1: DelegateCall) to `to` with `value` (Native Token) and return data
* @param to Destination address of module transaction.
Expand All @@ -64,6 +82,24 @@ interface IModuleManager {
Enum.Operation operation
) external returns (bool success, bytes memory returnData);

/**
* @notice Execute `operation` (0: Call, 1: DelegateCall) to `to` with `value` (Native Token) and return data
* @param to Destination address of module transaction.
* @param value Ether value of module transaction.
* @param data Data payload of module transaction.
* @param operation Operation type of module transaction.
* @param context Additional context information for the module transaction.
* @return success Boolean flag indicating if the call succeeded.
* @return returnData Data returned by the call.
*/
function execTransactionFromModuleReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
bytes calldata context
) external returns (bool success, bytes memory returnData);

/**
* @notice Returns if an module is enabled
* @return True if the module is enabled
Expand Down

0 comments on commit e90d07c

Please sign in to comment.