Skip to content

Commit

Permalink
L-05 [Oval] PermissionProxy.execute Will Fail if Non-Zero value Is Pr…
Browse files Browse the repository at this point in the history
…ovided (#20)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
  • Loading branch information
Reinis-FRP committed Jun 18, 2024
1 parent 0e94235 commit 77e5441
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/factories/PermissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Multicall} from "openzeppelin-contracts/contracts/utils/Multicall.sol";
*/
contract PermissionProxy is Ownable, Multicall {
error SenderNotApproved(address sender);
error CallFailed(address target, uint256 value, bytes callData);
error CallFailed(address target, bytes callData);

event SenderSet(address sender, bool allowed);

Expand All @@ -32,20 +32,19 @@ contract PermissionProxy is Ownable, Multicall {
* @notice Executes a call from this contract.
* @dev Can only be called by an allowed sender.
* @param target the address to call.
* @param value the value to send.
* @param callData the calldata to use for the call.
* @return the data returned by the external call.
*
*/
function execute(address target, uint256 value, bytes memory callData) external returns (bytes memory) {
function execute(address target, bytes memory callData) external returns (bytes memory) {
if (!senders[msg.sender]) {
revert SenderNotApproved(msg.sender);
}

(bool success, bytes memory returnData) = target.call{value: value}(callData);
(bool success, bytes memory returnData) = target.call{value: 0}(callData);

if (!success) {
revert CallFailed(target, value, callData);
revert CallFailed(target, callData);
}

return returnData;
Expand Down
15 changes: 7 additions & 8 deletions test/unit/PermissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ contract PermissionProxyTest is CommonTest {
PermissionProxy permissionProxy;
address mockAddress = address(0xdeadbeef);
bytes testCallData = abi.encodeWithSignature("foo()");
uint256 testValue = 1;
bytes returnData = abi.encode(uint256(7));

function setUp() public {
Expand All @@ -19,22 +18,22 @@ contract PermissionProxyTest is CommonTest {
function testSenderPermissions() public {
vm.prank(account2);
vm.expectRevert(abi.encodeWithSelector(PermissionProxy.SenderNotApproved.selector, account2));
permissionProxy.execute(mockAddress, testValue, testCallData);
permissionProxy.execute(mockAddress, testCallData);

vm.prank(account1);
vm.mockCall(mockAddress, testValue, testCallData, abi.encode(uint256(7)));
vm.expectCall(mockAddress, testValue, testCallData);
bytes memory actualReturnValue = permissionProxy.execute(mockAddress, testValue, testCallData);
vm.mockCall(mockAddress, testCallData, abi.encode(uint256(7)));
vm.expectCall(mockAddress, testCallData);
bytes memory actualReturnValue = permissionProxy.execute(mockAddress, testCallData);
assertEq0(actualReturnValue, returnData);
}

function testCallFailed() public {
vm.prank(account1);
vm.mockCallRevert(mockAddress, testValue, testCallData, "");
vm.mockCallRevert(mockAddress, testCallData, "");
vm.expectRevert(
abi.encodeWithSelector(PermissionProxy.CallFailed.selector, mockAddress, testValue, testCallData)
abi.encodeWithSelector(PermissionProxy.CallFailed.selector, mockAddress, testCallData)
);
permissionProxy.execute(mockAddress, testValue, testCallData);
permissionProxy.execute(mockAddress, testCallData);
}

function testSetSender() public {
Expand Down

0 comments on commit 77e5441

Please sign in to comment.