Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor decoding in permissionless handler #210

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions contracts/handlers/PermissionlessGenericHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ contract PermissionlessGenericHandler is IHandler {
uint8 lenExecutionDataDepositor;
address executionDataDepositor;

maxFee = uint256(bytes32(data[:32]));
lenExecuteFuncSignature = uint16(bytes2(data[32:34]));
lenExecuteContractAddress = uint8(bytes1(data[34 + lenExecuteFuncSignature:35 + lenExecuteFuncSignature]));
lenExecutionDataDepositor = uint8(bytes1(data[35 + lenExecuteFuncSignature + lenExecuteContractAddress:36 + lenExecuteFuncSignature + lenExecuteContractAddress]));
executionDataDepositor = address(uint160(bytes20(data[36 + lenExecuteFuncSignature + lenExecuteContractAddress:36 + lenExecuteFuncSignature + lenExecuteContractAddress + lenExecutionDataDepositor])));
uint256 pointer = 0;

maxFee = uint256(bytes32(data[:pointer += 32]));
lenExecuteFuncSignature = uint16(bytes2(data[pointer:pointer += 2]));
pointer += lenExecuteFuncSignature;
lenExecuteContractAddress = uint8(bytes1(data[pointer:pointer += 1]));
pointer += lenExecuteContractAddress;
lenExecutionDataDepositor = uint8(bytes1(data[pointer:pointer += 1]));
executionDataDepositor = address(uint160(bytes20(data[pointer:pointer + lenExecutionDataDepositor])));

require(maxFee < MAX_FEE, 'requested fee too large');
require(depositor == executionDataDepositor, 'incorrect depositor in deposit data');
Expand Down Expand Up @@ -156,15 +160,17 @@ contract PermissionlessGenericHandler is IHandler {
uint8 lenExecutionDataDepositor;
address executionDataDepositor;
bytes memory executionData;

maxFee = uint256(bytes32(data[0:32]));
lenExecuteFuncSignature = uint16(bytes2(data[32:34]));
executeFuncSignature = bytes4(data[34:34 + lenExecuteFuncSignature]);
lenExecuteContractAddress = uint8(bytes1(data[34 + lenExecuteFuncSignature:35 + lenExecuteFuncSignature]));
executeContractAddress = address(uint160(bytes20(data[35 + lenExecuteFuncSignature:35 + lenExecuteFuncSignature + lenExecuteContractAddress])));
lenExecutionDataDepositor = uint8(bytes1(data[35 + lenExecuteFuncSignature + lenExecuteContractAddress:36 + lenExecuteFuncSignature + lenExecuteContractAddress]));
executionDataDepositor = address(uint160(bytes20(data[36 + lenExecuteFuncSignature + lenExecuteContractAddress:36 + lenExecuteFuncSignature + lenExecuteContractAddress + lenExecutionDataDepositor])));
executionData = bytes(data[36 + lenExecuteFuncSignature + lenExecuteContractAddress + lenExecutionDataDepositor:]);

uint256 pointer = 0;

maxFee = uint256(bytes32(data[:pointer += 32]));
lenExecuteFuncSignature = uint16(bytes2(data[pointer:pointer += 2]));
executeFuncSignature = bytes4(data[pointer:pointer += lenExecuteFuncSignature]);
lenExecuteContractAddress = uint8(bytes1(data[pointer:pointer += 1]));
executeContractAddress = address(uint160(bytes20(data[pointer:pointer += lenExecuteContractAddress])));
lenExecutionDataDepositor = uint8(bytes1(data[pointer:pointer += 1]));
executionDataDepositor = address(uint160(bytes20(data[pointer:pointer += lenExecutionDataDepositor])));
executionData = bytes(data[pointer:]);

bytes memory callData = abi.encodePacked(executeFuncSignature, abi.encode(executionDataDepositor), executionData);
(bool success, bytes memory returndata) = executeContractAddress.call{gas: maxFee}(callData);
Expand Down
Loading