Skip to content

Commit

Permalink
refactor: adjust + re-order checks for main controller
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Aug 21, 2023
1 parent 75681b0 commit 3c98d62
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract contract LSP6ExecuteModule {
uint256 value,
bytes memory data
) internal view virtual {
bool isTransferringValue = value != 0;
bool isValueTransfer = value != 0;

bool hasSuperTransferValue = permissions.hasPermission(
_PERMISSION_SUPER_TRANSFERVALUE
Expand All @@ -199,17 +199,20 @@ abstract contract LSP6ExecuteModule {

bool hasSuperCall = permissions.hasPermission(_PERMISSION_SUPER_CALL);

if (isTransferringValue && !hasSuperTransferValue) {
if (isValueTransfer && !hasSuperTransferValue) {
_requirePermissions(
controller,
permissions,
_PERMISSION_TRANSFERVALUE
);
}

// Skip if both SUPER permissions are present
if (hasSuperCall && hasSuperTransferValue) return;

// CHECK if we are doing an empty call, as the receive() or fallback() function
// of the controlledContract could run some code.
if (!hasSuperCall && isEmptyCall && !isTransferringValue) {
if (isEmptyCall && !isValueTransfer && !hasSuperCall) {
_requirePermissions(controller, permissions, _PERMISSION_CALL);
}

Expand All @@ -218,13 +221,10 @@ abstract contract LSP6ExecuteModule {
}

// Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
if (hasSuperCall && !isTransferringValue) return;
if (!isValueTransfer && hasSuperCall) return;

// Skip if caller has SUPER permission for value transfers
if (hasSuperTransferValue && isEmptyCall && isTransferringValue) return;

// Skip if both SUPER permissions are present
if (hasSuperCall && hasSuperTransferValue) return;
if (isEmptyCall && isValueTransfer && hasSuperTransferValue) return;

_verifyAllowedCall(
controlledContract,
Expand All @@ -244,11 +244,6 @@ abstract contract LSP6ExecuteModule {
uint256 value,
bytes memory data
) internal view virtual {
bool isEmptyCall = data.length == 0;

// CHECK if there is at least a 4 bytes function selector
bytes4 selector = data.length >= 4 ? bytes4(data) : bytes4(0);

// CHECK for ALLOWED CALLS
bytes memory allowedCalls = ERC725Y(controlledContract)
.getAllowedCallsFor(controllerAddress);
Expand All @@ -257,6 +252,11 @@ abstract contract LSP6ExecuteModule {
revert NoCallsAllowed(controllerAddress);
}

bool isEmptyCall = data.length == 0;

// CHECK if there is at least a 4 bytes function selector
bytes4 selector = data.length >= 4 ? bytes4(data) : bytes4(0);

bytes4 requiredCallTypes = _extractCallType(
operationType,
value,
Expand Down

0 comments on commit 3c98d62

Please sign in to comment.