Skip to content

Commit

Permalink
Check valid function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
hiep-immutable committed Aug 26, 2024
1 parent 144f688 commit 820ab85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
23 changes: 10 additions & 13 deletions contracts/multicall/GuardedMulticaller2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,26 @@ contract GuardedMulticaller2 is AccessControl, ReentrancyGuard, EIP712 {
/// @dev Error thrown when reference has already been executed
error ReusedReference(bytes32 _reference);

/// @dev Error thrown when call array is empty
error EmptyCallArray();

/// @dev Error thrown when address array and data array have different lengths
error AddressDataArrayLengthsMismatch(uint256 _addressLength, uint256 _dataLength);

/// @dev Error thrown when deadline is expired
error Expired(uint256 _deadline);

/// @dev Error thrown when target address is not a contract
error NonContractAddress(Call _call);

/// @dev Error thrown when signer is not authorized
error UnauthorizedSigner(address _multicallSigner);

/// @dev Error thrown when signature is invalid
error UnauthorizedSignature(bytes _signature);

/// @dev Error thrown when call array is empty
error EmptyCallArray();

/// @dev Error thrown when call reverts
error FailedCall(Call _call);

/// @dev Error thrown when call data is invalid
error InvalidCallData(address _target, bytes _data);
/// @dev Error thrown when target address is not a contract
error NonContractAddress(Call _call);

/// @dev Error thrown when call data is unauthorized
error UnauthorizedFunction(address _target, string _functionSignature);
/// @dev Error thrown when function signature is invalid
error InvalidFunctionSignature(Call _call);

/**
*
Expand Down Expand Up @@ -135,6 +129,9 @@ contract GuardedMulticaller2 is AccessControl, ReentrancyGuard, EIP712 {
revert EmptyCallArray();
}
for (uint256 i = 0; i < _calls.length; i++) {
if (bytes(_calls[i].functionSignature).length == 0) {
revert InvalidFunctionSignature(_calls[i]);
}
if (_calls[i].target.code.length == 0) {
revert NonContractAddress(_calls[i]);
}
Expand Down
15 changes: 15 additions & 0 deletions test/multicall/GuardedMulticaller2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,19 @@ contract GuardedMulticaller2Test is Test {

gmc.execute(signer, ref, calls, deadline, signature);
}

function test_RevertWhen_ExecuteInvalidFunctionSignature() public {
bytes32 ref = keccak256("ref");
uint256 deadline = block.timestamp + 1;
GuardedMulticaller2.Call[] memory calls = new GuardedMulticaller2.Call[](1);
calls[0] = GuardedMulticaller2.Call(address(target), "", abi.encodePacked(uint256(42)));

bytes32 digest = sigUtils.hashTypedData(ref, calls, deadline);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signerPk, digest);
bytes memory signature = abi.encodePacked(r, s, v);

vm.expectRevert(abi.encodeWithSelector(GuardedMulticaller2.InvalidFunctionSignature.selector, calls[0]));

gmc.execute(signer, ref, calls, deadline, signature);
}
}

0 comments on commit 820ab85

Please sign in to comment.