Skip to content

Commit

Permalink
[#4] WIP: Add events, errors, logic in protocol mediator
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jun 20, 2023
1 parent 96f2067 commit 6546e17
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contracts/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.18;

struct SafeProtocolAction {
address to;
address payable to;
uint256 value;
bytes data;
}
Expand Down
58 changes: 54 additions & 4 deletions contracts/SafeProtocolMediator.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;
import {ISafeProtocolMediator} from "./interfaces/Mediator.sol";
import {ISafeProtocolModule} from "./interfaces/Components.sol";

import {ISafe} from "./interfaces/Accounts.sol";
import "./DataTypes.sol";

Check warning on line 7 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

global import of path ./DataTypes.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import "@openzeppelin/contracts/access/Ownable2Step.sol";

Check warning on line 8 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

global import of path @openzeppelin/contracts/access/Ownable2Step.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

/**
* @title
* @notice
* @title TODO
* @notice TODO
*/
contract SafeProtocolMediator is ISafeProtocolMediator, Ownable2Step {

Check failure on line 15 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace ⏎····mapping· with ····mapping
mapping (address => uint) public nonces;

Check failure on line 17 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Delete ····
event ActionsExecuted(address safe, bytes32 metaHash);
event RootAccessActionsExecuted(address safe, bytes32 metaHash);

error InvalidNonce(address sender, uint256 nonce);
error ModuleRequiresRootAccess(address sender);

constructor(address initalOwner) {
_transferOwnership(initalOwner);
}
Expand All @@ -24,7 +35,28 @@ contract SafeProtocolMediator is ISafeProtocolMediator, Ownable2Step {
function executeTransaction(
ISafe safe,
SafeTransaction calldata transaction
) external view override returns (bool success, bytes[] memory data) {}
) external override returns (bool success, bytes[] memory data) {
// TODO: Check for re-entrancy attacks
// TODO: Validate metahash

if(ISafeProtocolModule(msg.sender).requiresRootAccess()){

Check failure on line 42 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace (ISafeProtocolModule(msg.sender).requiresRootAccess()) with ·(ISafeProtocolModule(msg.sender).requiresRootAccess())·
revert ModuleRequiresRootAccess(msg.sender);
}

if(nonces[msg.sender] != transaction.nonce){

Check failure on line 46 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace (nonces[msg.sender]·!=·transaction.nonce) with ·(nonces[msg.sender]·!=·transaction.nonce)·
revert InvalidNonce(msg.sender, transaction.nonce);
}

Check failure on line 49 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Delete ········
nonces[msg.sender]++;

data = new bytes[](transaction.actions.length);
for (uint256 i = 0; i < transaction.actions.length; ++i) {
SafeProtocolAction memory safeProtocolAction = transaction.actions[i];
//TODO: Set data variable or update documentation
safe.execTransactionFromModule(safeProtocolAction.to, safeProtocolAction.value, safeProtocolAction.data, 0);
}
success = true;
}

/**
* @notice TODO
Expand All @@ -36,5 +68,23 @@ contract SafeProtocolMediator is ISafeProtocolMediator, Ownable2Step {
function executeRootAccess(

Check failure on line 68 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace ⏎········ISafe·safe,⏎········SafeRootAccess·calldata·rootAccess⏎···· with ISafe·safe,·SafeRootAccess·calldata·rootAccess
ISafe safe,
SafeRootAccess calldata rootAccess
) external view override returns (bool success, bytes[] memory data) {}
) external override returns (bool success, bytes memory data) {
SafeProtocolAction memory safeProtocolAction = rootAccess.action;
// TODO: Set data variable or update documentation
// TODO: Check for re-entrancy attacks
// TODO: Validate metahash

// Re-confirm if this check if needed and correct.
if(!ISafeProtocolModule(msg.sender).requiresRootAccess()){

Check failure on line 78 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace (!ISafeProtocolModule(msg.sender).requiresRootAccess()) with ·(!ISafeProtocolModule(msg.sender).requiresRootAccess())·
revert ModuleRequiresRootAccess(msg.sender);
}

if(nonces[msg.sender] != rootAccess.nonce){

Check failure on line 82 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Replace (nonces[msg.sender]·!=·rootAccess.nonce) with ·(nonces[msg.sender]·!=·rootAccess.nonce)·
revert InvalidNonce(msg.sender, rootAccess.nonce);
}

Check failure on line 85 in contracts/SafeProtocolMediator.sol

View workflow job for this annotation

GitHub Actions / lint

Delete ········
nonces[msg.sender]++;
data = "";
success = safe.execTransactionFromModule(safeProtocolAction.to, safeProtocolAction.value, safeProtocolAction.data, 1);
}
}
4 changes: 2 additions & 2 deletions contracts/interfaces/Mediator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ISafeProtocolMediator {
* @return data Array of bytes types returned upon the successful execution of all the actions. Size of array will be same as size of actions
* in case of succcessful execution. Empty if the call failed.
*/
function executeTransaction(ISafe safe, SafeTransaction calldata transaction) external view returns (bool success, bytes[] memory data);
function executeTransaction(ISafe safe, SafeTransaction calldata transaction) external returns (bool success, bytes[] memory data);

/**
* @notice TODO
Expand All @@ -28,5 +28,5 @@ interface ISafeProtocolMediator {
* @return data Arbitrary length bytes data returned upon the successful execution. Size of array will be same as size of actions
* in case of succcessful execution. Empty if the call failed.
*/
function executeRootAccess(ISafe safe, SafeRootAccess calldata rootAccess) external view returns (bool success, bytes[] memory data);
function executeRootAccess(ISafe safe, SafeRootAccess calldata rootAccess) external returns (bool success, bytes memory data);
}
2 changes: 1 addition & 1 deletion contracts/test/TestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract contract BaseTestModule is ISafeProtocolModule {
}

contract TestModule is BaseTestModule {
function executeFromModule(ISafe safe, address payable to, uint256 value,bytes calldata data) external {
function executeFromModule(ISafe safe, address payable to, uint256 value, bytes calldata data) external {
safe.execTransactionFromModule(to, value, data, 0);
}
}
Expand Down

0 comments on commit 6546e17

Please sign in to comment.