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: optimize Base module a bit #261

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
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:]);
}
}
Loading