Skip to content

Commit

Permalink
chore: optimize Base module a bit (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangting-alchemy authored Oct 16, 2024
1 parent cb58eb8 commit 7342b19
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
423918
423482
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79484
78838
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113042
112223
Original file line number Diff line number Diff line change
@@ -1 +1 @@
532152
531716
Original file line number Diff line number Diff line change
@@ -1 +1 @@
195938
195559
Original file line number Diff line number Diff line change
@@ -1 +1 @@
227062
226591
Original file line number Diff line number Diff line change
@@ -1 +1 @@
422598
422162
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79900
79254
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113458
112639
Original file line number Diff line number Diff line change
@@ -1 +1 @@
529725
529289
Original file line number Diff line number Diff line change
@@ -1 +1 @@
196232
195853
Original file line number Diff line number Diff line change
@@ -1 +1 @@
227368
226897
28 changes: 15 additions & 13 deletions src/modules/BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,26 @@ abstract contract BaseModule is ERC165, IModule {
/// @dev help method that returns extracted selector and calldata. If selector is executeUserOp, return the
/// selector and calldata of the inner call.
function _getSelectorAndCalldata(bytes calldata data) internal pure returns (bytes4, bytes memory) {
if (bytes4(data[:4]) == IAccountExecute.executeUserOp.selector) {
bytes4 selector = bytes4(data[:4]);
if (selector == IAccountExecute.executeUserOp.selector) {
(PackedUserOperation memory uo,) = abi.decode(data[4:], (PackedUserOperation, bytes32));
bytes4 selector;
bytes memory callData = uo.callData;
bytes memory finalCalldata = uo.callData;
// Bytes arr representation: [bytes32(len), bytes4(executeUserOp.selector), bytes4(actualSelector),
// bytes(actualCallData)]
// 1. Copy actualSelector into a new var
// 2. Shorten bytes arry by 8 by: store length - 8 into the new pointer location
// 3. Move the callData pointer by 8
assembly {
selector := mload(add(callData, 36))
assembly ("memory-safe") {
// Copy actualSelector into a new var
selector := shl(224, mload(add(finalCalldata, 8)))

let len := mload(callData)
mstore(add(callData, 8), sub(len, 8))
callData := add(callData, 8)
let len := mload(finalCalldata)

// Move the finalCalldata pointer by 8
finalCalldata := add(finalCalldata, 8)

// Shorten bytes arry by 8 by: store length - 8 into the new pointer location
mstore(finalCalldata, sub(len, 8))
}
return (selector, callData);
return (selector, finalCalldata);
}
return (bytes4(data[:4]), data[4:]);
return (selector, data[4:]);
}
}

0 comments on commit 7342b19

Please sign in to comment.