From 357e5675f6f06bc6980ed25f0fe2a03931500efc Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 10 Oct 2024 18:55:51 -0400 Subject: [PATCH] feat: transient self-call memory in RT validation --- .../ModularAccount_Runtime_BatchTransfers.snap | 2 +- .../ModularAccount_Runtime_Erc20Transfer.snap | 2 +- ...dularAccount_Runtime_InstallSessionKey_Case1.snap | 2 +- .../ModularAccount_Runtime_NativeTransfer.snap | 2 +- ...rAccount_Runtime_UseSessionKey_Case1_Counter.snap | 2 +- ...larAccount_Runtime_UseSessionKey_Case1_Token.snap | 2 +- .../SemiModularAccount_Runtime_BatchTransfers.snap | 2 +- .../SemiModularAccount_Runtime_Erc20Transfer.snap | 2 +- ...dularAccount_Runtime_InstallSessionKey_Case1.snap | 2 +- .../SemiModularAccount_Runtime_NativeTransfer.snap | 2 +- ...rAccount_Runtime_UseSessionKey_Case1_Counter.snap | 2 +- ...larAccount_Runtime_UseSessionKey_Case1_Token.snap | 2 +- src/account/ModularAccountBase.sol | 12 +++--------- src/libraries/ExecutionLib.sol | 9 +++++---- 14 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.forge-snapshots/ModularAccount_Runtime_BatchTransfers.snap b/.forge-snapshots/ModularAccount_Runtime_BatchTransfers.snap index 81620e08b..5aa810a83 100644 --- a/.forge-snapshots/ModularAccount_Runtime_BatchTransfers.snap +++ b/.forge-snapshots/ModularAccount_Runtime_BatchTransfers.snap @@ -1 +1 @@ -93127 \ No newline at end of file +93118 \ No newline at end of file diff --git a/.forge-snapshots/ModularAccount_Runtime_Erc20Transfer.snap b/.forge-snapshots/ModularAccount_Runtime_Erc20Transfer.snap index b40fed9a0..b4ea1b66f 100644 --- a/.forge-snapshots/ModularAccount_Runtime_Erc20Transfer.snap +++ b/.forge-snapshots/ModularAccount_Runtime_Erc20Transfer.snap @@ -1 +1 @@ -78552 \ No newline at end of file +78543 \ No newline at end of file diff --git a/.forge-snapshots/ModularAccount_Runtime_InstallSessionKey_Case1.snap b/.forge-snapshots/ModularAccount_Runtime_InstallSessionKey_Case1.snap index b5f4c9d08..13bdc794f 100644 --- a/.forge-snapshots/ModularAccount_Runtime_InstallSessionKey_Case1.snap +++ b/.forge-snapshots/ModularAccount_Runtime_InstallSessionKey_Case1.snap @@ -1 +1 @@ -424043 \ No newline at end of file +424034 \ No newline at end of file diff --git a/.forge-snapshots/ModularAccount_Runtime_NativeTransfer.snap b/.forge-snapshots/ModularAccount_Runtime_NativeTransfer.snap index a51d6cdbb..c1b5decaf 100644 --- a/.forge-snapshots/ModularAccount_Runtime_NativeTransfer.snap +++ b/.forge-snapshots/ModularAccount_Runtime_NativeTransfer.snap @@ -1 +1 @@ -54701 \ No newline at end of file +54692 \ No newline at end of file diff --git a/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Counter.snap b/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Counter.snap index b11e38a41..ea6db0041 100644 --- a/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Counter.snap +++ b/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Counter.snap @@ -1 +1 @@ -79540 \ No newline at end of file +79531 \ No newline at end of file diff --git a/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Token.snap b/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Token.snap index 64354daac..c924bddf5 100644 --- a/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Token.snap +++ b/.forge-snapshots/ModularAccount_Runtime_UseSessionKey_Case1_Token.snap @@ -1 +1 @@ -113098 \ No newline at end of file +113089 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_BatchTransfers.snap b/.forge-snapshots/SemiModularAccount_Runtime_BatchTransfers.snap index 134271761..5ed4b1238 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_BatchTransfers.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_BatchTransfers.snap @@ -1 +1 @@ -89614 \ No newline at end of file +89286 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_Erc20Transfer.snap b/.forge-snapshots/SemiModularAccount_Runtime_Erc20Transfer.snap index 77e65f141..1325eed1c 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_Erc20Transfer.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_Erc20Transfer.snap @@ -1 +1 @@ -75094 \ No newline at end of file +74791 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_InstallSessionKey_Case1.snap b/.forge-snapshots/SemiModularAccount_Runtime_InstallSessionKey_Case1.snap index 4adee42c2..663b4046c 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_InstallSessionKey_Case1.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_InstallSessionKey_Case1.snap @@ -1 +1 @@ -423069 \ No newline at end of file +422778 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_NativeTransfer.snap b/.forge-snapshots/SemiModularAccount_Runtime_NativeTransfer.snap index f7cde7586..57af4b6e4 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_NativeTransfer.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_NativeTransfer.snap @@ -1 +1 @@ -51244 \ No newline at end of file +50950 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Counter.snap b/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Counter.snap index cb3462b52..faf693d81 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Counter.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Counter.snap @@ -1 +1 @@ -80038 \ No newline at end of file +80029 \ No newline at end of file diff --git a/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Token.snap b/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Token.snap index b51b43bf0..68ed10e94 100644 --- a/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Token.snap +++ b/.forge-snapshots/SemiModularAccount_Runtime_UseSessionKey_Case1_Token.snap @@ -1 +1 @@ -113596 \ No newline at end of file +113587 \ No newline at end of file diff --git a/src/account/ModularAccountBase.sol b/src/account/ModularAccountBase.sol index 75f14eb69..6421767b5 100644 --- a/src/account/ModularAccountBase.sol +++ b/src/account/ModularAccountBase.sol @@ -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); @@ -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); diff --git a/src/libraries/ExecutionLib.sol b/src/libraries/ExecutionLib.sol index 467c5e663..77d057ef9 100644 --- a/src/libraries/ExecutionLib.sol +++ b/src/libraries/ExecutionLib.sol @@ -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") { @@ -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); } }