Skip to content

Commit

Permalink
chore: guarded call -> blocked call
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed Jun 24, 2024
1 parent 84abd74 commit 695a4ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/RumpelGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract RumpelGuard is AccessControl, IGuard {
}

function setCallPermenantlyAllowed(address target, bytes4 functionSig) public onlyRole(DEFAULT_ADMIN_ROLE) {
permanentlyAllowedTargets[target][functionSig] = true;
permanentlyAllowedTargets[target][functionSig] = true; // One way, only true
emit SetCallPermenantlyAllowed(target, functionSig);
}

Expand Down
21 changes: 10 additions & 11 deletions src/RumpelModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {Enum} from "./interfaces/external/ISafe.sol";
import {ISafe} from "./interfaces/external/ISafe.sol";

contract RumpelModule is AccessControl {
error CallGuarded(address target, bytes4 data);
error CallBlocked(address target, bytes4 data);
error ExecFailed(address safe, address target, bytes data);

event ExecutionFromModule(address indexed safe, address indexed target, uint256 value, bytes data);
event TokensSwepped(address indexed safe, address indexed token, uint256 amount);
event RumpelVaultUpdated(address indexed newVault);
event GuardedCallAdded(address indexed target, bytes4 indexed data);
event BlockedCallAdded(address indexed target, bytes4 indexed data);

mapping(address => mapping(bytes4 => bool)) public guardedCalls;
mapping(address => mapping(bytes4 => bool)) public blockedCalls;
bytes32 public constant SWEEPER_ROLE = keccak256("SWEEPER_ROLE");
address public rumpelVault;

Expand Down Expand Up @@ -44,9 +44,9 @@ contract RumpelModule is AccessControl {
*/
function exec(Call[] memory calls) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
for (uint256 i = 0; i < calls.length; i++) {
if (guardedCalls[calls[i].to][bytes4(calls[i].data)]) {
if (blockedCalls[calls[i].to][bytes4(calls[i].data)]) {
// Calls that the module is prevented from making
revert CallGuarded(calls[i].to, bytes4(calls[i].data));
revert CallBlocked(calls[i].to, bytes4(calls[i].data));
}
// TODO: what about eth trasnfers?

Expand Down Expand Up @@ -80,13 +80,12 @@ contract RumpelModule is AccessControl {
// Admin ---

/**
* @dev Add a protected call to prevent it from being executed via the module.
* Useful so that for e.g. DAI or USDC, users can be assured that the
* RumpelModule will never transfer their tokens.
* @dev Add address.call to prevent it from being executed via the module.
* Useful as an assurance that the RumpelModule will never e.g. transfer a user's USDC.
*/
function addGuardedCall(address to, bytes4 data) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
guardedCalls[to][data] = true;
emit GuardedCallAdded(to, data);
function addBlockedCall(address to, bytes4 data) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
blockedCalls[to][data] = true;
emit BlockedCallAdded(to, data);
}

function setRumpelVault(address _rumpelVault) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
Expand Down
4 changes: 2 additions & 2 deletions test/RumpelWallet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ contract RumpelWalletTest is Test {

// Guard the transfer call
vm.prank(admin);
rumpelModule.addGuardedCall(address(mockToken), ERC20.transfer.selector);
rumpelModule.addBlockedCall(address(mockToken), ERC20.transfer.selector);

// Attempt to execute the guarded call
vm.expectRevert(
abi.encodeWithSelector(
RumpelModule.CallGuarded.selector,
RumpelModule.CallBlocked.selector,
address(mockToken),
bytes4(abi.encodeCall(ERC20.transfer, (RUMPEL_VAULT, 1e18)))
)
Expand Down

0 comments on commit 695a4ec

Please sign in to comment.