diff --git a/.forge-snapshots/addLiquidity CA fee.snap b/.forge-snapshots/addLiquidity CA fee.snap index 97fe666ae..f0f83af59 100644 --- a/.forge-snapshots/addLiquidity CA fee.snap +++ b/.forge-snapshots/addLiquidity CA fee.snap @@ -1 +1 @@ -325929 \ No newline at end of file +325681 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with empty hook.snap b/.forge-snapshots/addLiquidity with empty hook.snap index 8b73e3f68..321b75523 100644 --- a/.forge-snapshots/addLiquidity with empty hook.snap +++ b/.forge-snapshots/addLiquidity with empty hook.snap @@ -1 +1 @@ -280141 \ No newline at end of file +279677 \ No newline at end of file diff --git a/.forge-snapshots/poolManager bytecode size.snap b/.forge-snapshots/poolManager bytecode size.snap index 6223b8f8e..209c7964e 100644 --- a/.forge-snapshots/poolManager bytecode size.snap +++ b/.forge-snapshots/poolManager bytecode size.snap @@ -1 +1 @@ -19837 \ No newline at end of file +19769 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity CA fee.snap b/.forge-snapshots/removeLiquidity CA fee.snap index 8b467bd55..ef18e73d8 100644 --- a/.forge-snapshots/removeLiquidity CA fee.snap +++ b/.forge-snapshots/removeLiquidity CA fee.snap @@ -1 +1 @@ -181448 \ No newline at end of file +181200 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity with empty hook.snap b/.forge-snapshots/removeLiquidity with empty hook.snap index 4669934d9..64e5b0f2b 100644 --- a/.forge-snapshots/removeLiquidity with empty hook.snap +++ b/.forge-snapshots/removeLiquidity with empty hook.snap @@ -1 +1 @@ -135835 \ No newline at end of file +135371 \ No newline at end of file diff --git a/.forge-snapshots/swap CA custom curve + swap noop.snap b/.forge-snapshots/swap CA custom curve + swap noop.snap index 549b44563..cb11d3cf2 100644 --- a/.forge-snapshots/swap CA custom curve + swap noop.snap +++ b/.forge-snapshots/swap CA custom curve + swap noop.snap @@ -1 +1 @@ -131947 \ No newline at end of file +131734 \ No newline at end of file diff --git a/.forge-snapshots/swap CA fee on unspecified.snap b/.forge-snapshots/swap CA fee on unspecified.snap index f0d54d019..8de3974f5 100644 --- a/.forge-snapshots/swap CA fee on unspecified.snap +++ b/.forge-snapshots/swap CA fee on unspecified.snap @@ -1 +1 @@ -178853 \ No newline at end of file +178608 \ No newline at end of file diff --git a/.forge-snapshots/swap skips hook call if hook is caller.snap b/.forge-snapshots/swap skips hook call if hook is caller.snap index eed7e7aeb..a2cb939b5 100644 --- a/.forge-snapshots/swap skips hook call if hook is caller.snap +++ b/.forge-snapshots/swap skips hook call if hook is caller.snap @@ -1 +1 @@ -216627 \ No newline at end of file +216411 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index 317026308..a6bec88bb 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -138307 \ No newline at end of file +137849 \ No newline at end of file diff --git a/.forge-snapshots/swap with lp fee and protocol fee.snap b/.forge-snapshots/swap with lp fee and protocol fee.snap index 3c9fccc6a..85dca1609 100644 --- a/.forge-snapshots/swap with lp fee and protocol fee.snap +++ b/.forge-snapshots/swap with lp fee and protocol fee.snap @@ -1 +1 @@ -175673 \ No newline at end of file +175460 \ No newline at end of file diff --git a/.forge-snapshots/swap with return dynamic fee.snap b/.forge-snapshots/swap with return dynamic fee.snap index 9f864527c..5aa307d47 100644 --- a/.forge-snapshots/swap with return dynamic fee.snap +++ b/.forge-snapshots/swap with return dynamic fee.snap @@ -1 +1 @@ -151773 \ No newline at end of file +151560 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index 46d558e0c..095ecab96 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -154415 \ No newline at end of file +154202 \ No newline at end of file diff --git a/src/libraries/Hooks.sol b/src/libraries/Hooks.sol index 44a89f242..5ade806e5 100644 --- a/src/libraries/Hooks.sol +++ b/src/libraries/Hooks.sol @@ -127,9 +127,27 @@ library Hooks { /// @notice performs a hook call using the given calldata on the given hook that doesnt return a delta /// @return result The complete data returned by the hook function callHook(IHooks self, bytes memory data) internal returns (bytes memory result) { - bool success; - (success, result) = address(self).call(data); - if (!success) _revert(result); + /// @solidity memory-safe-assembly + assembly { + if iszero(call(gas(), self, 0, add(data, 0x20), mload(data), 0, 0)) { + if iszero(returndatasize()) { + // if the call failed without a revert reason, revert with `FailedHookCall()` + mstore(0, 0x36bc48c5) + revert(0x1c, 0x04) + } + // bubble up revert + returndatacopy(0, 0, returndatasize()) + revert(0, returndatasize()) + } + // allocate result byte array from the free memory pointer + result := mload(0x40) + // store new free memory pointer at the end of the array padded to 32 bytes + mstore(0x40, add(result, and(add(returndatasize(), 0x3f), not(0x1f)))) + // store length in memory + mstore(result, returndatasize()) + // copy return data to result + returndatacopy(add(result, 0x20), 0, returndatasize()) + } // Check expected selector and returned selector match. if (result.parseSelector() != data.parseSelector()) InvalidHookResponse.selector.revertWith(); @@ -322,12 +340,4 @@ library Hooks { function hasPermission(IHooks self, uint160 flag) internal pure returns (bool) { return uint160(address(self)) & flag != 0; } - - /// @notice bubble up revert if present. Else throw FailedHookCall - function _revert(bytes memory result) private pure { - if (result.length == 0) FailedHookCall.selector.revertWith(); - assembly { - revert(add(0x20, result), mload(result)) - } - } }