Skip to content

Commit

Permalink
feat: transient self-call memory in RT validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Oct 11, 2024
1 parent 8a95166 commit 357e567
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93127
93118
2 changes: 1 addition & 1 deletion .forge-snapshots/ModularAccount_Runtime_Erc20Transfer.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
78552
78543
Original file line number Diff line number Diff line change
@@ -1 +1 @@
424043
424034
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54701
54692
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79540
79531
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113098
113089
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89614
89286
Original file line number Diff line number Diff line change
@@ -1 +1 @@
75094
74791
Original file line number Diff line number Diff line change
@@ -1 +1 @@
423069
422778
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51244
50950
Original file line number Diff line number Diff line change
@@ -1 +1 @@
80038
80029
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113596
113587
12 changes: 3 additions & 9 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,8 @@ abstract contract ModularAccountBase is
DensePostHookData postHookData = _checkPermittedCallerAndAssociatedHooks();

// execute the function, bubbling up any reverts
(bool execSuccess, bytes memory execReturnData) = execModule.call(msg.data);

if (!execSuccess) {
// Bubble up revert reasons from modules
assembly ("memory-safe") {
revert(add(execReturnData, 32), mload(execReturnData))
}
}
ExecutionLib.callBubbleOnRevertTransient(execModule, 0 wei, msg.data);
bytes memory execReturnData = ExecutionLib.collectReturnData();

ExecutionLib.doCachedPostHooks(postHookData);

Expand Down Expand Up @@ -315,7 +309,7 @@ abstract contract ModularAccountBase is

// Execute the call, reusing the already-allocated RT call buffers, if it exists.
// In practice, this is cheaper than attempting to coalesce the (possibly two) buffers.
ExecutionLib.callBubbleOnRevert(address(this), 0 wei, ExecutionLib.getCallData(rtCallBuffer, data));
ExecutionLib.executeRuntimeSelfCall(rtCallBuffer, data);
bytes memory returnData = ExecutionLib.collectReturnData();

ExecutionLib.doCachedPostHooks(postHookData);
Expand Down
9 changes: 5 additions & 4 deletions src/libraries/ExecutionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ library ExecutionLib {
}
}

function getCallData(RTCallBuffer buffer, bytes calldata data) internal pure returns (bytes memory) {
function executeRuntimeSelfCall(RTCallBuffer buffer, bytes calldata data) internal {
bool bufferExists;

assembly ("memory-safe") {
Expand All @@ -457,10 +457,11 @@ library ExecutionLib {
callData := add(buffer, 0xe4)
}

return callData;
// Perform the call, bubbling up revert data on failure.
callBubbleOnRevert(address(this), 0, callData);
} else {
// No buffer exists yet, just copy the data to memory and return it.
return data;
// No buffer exists yet, just copy the data to memory transiently and execute it.
callBubbleOnRevertTransient(address(this), 0, data);
}
}

Expand Down

0 comments on commit 357e567

Please sign in to comment.