diff --git a/src/common/implementation/TryMulticall.sol b/src/common/implementation/TryMulticall.sol index f7cd4eb..187e829 100644 --- a/src/common/implementation/TryMulticall.sol +++ b/src/common/implementation/TryMulticall.sol @@ -6,7 +6,14 @@ pragma solidity ^0.8.27; * @notice Executes allowed self-delegatecalls without reverting successful siblings. */ abstract contract TryMulticall { - bool private _tryMulticallEntered; + /// @custom:storage-location erc7201:uma.storage.TryMulticall + struct TryMulticallStorage { + bool entered; + } + + // keccak256(abi.encode(uint256(keccak256("uma.storage.TryMulticall")) - 1)) & ~bytes32(uint256(0xff)) + bytes32 private constant TRY_MULTICALL_STORAGE_LOCATION = + 0x0dd1bd2d495db0d62878fd399d4ab6dc237ff1584371e8862b3e045d79dcd000; /// @notice Emitted when a child execution attempt returns unsuccessfully. /// @dev Empty failure metadata can mean either an empty revert or an out-of-gas child. This event does not prove @@ -28,7 +35,8 @@ abstract contract TryMulticall { */ function tryMulticall(bytes[] calldata calls) external returns (bool[] memory successes) { _checkTryMulticallCaller(); - if (_tryMulticallEntered) revert TryMulticallReentrantCall(); + TryMulticallStorage storage $ = _getTryMulticallStorage(); + if ($.entered) revert TryMulticallReentrantCall(); uint256 callsLength = calls.length; bytes4 allowedSelector = _tryMulticallSelector(); @@ -39,7 +47,7 @@ abstract contract TryMulticall { } successes = new bool[](callsLength); - _tryMulticallEntered = true; + $.entered = true; for (uint256 i; i < callsLength; ++i) { bytes calldata callData = calls[i]; (bool success, bytes memory revertData) = address(this).delegatecall(callData); @@ -50,7 +58,13 @@ abstract contract TryMulticall { emit ProposalCallFailed(i, keccak256(callData), errorSelector, keccak256(revertData)); } } - _tryMulticallEntered = false; + $.entered = false; + } + + function _getTryMulticallStorage() private pure returns (TryMulticallStorage storage $) { + assembly { + $.slot := TRY_MULTICALL_STORAGE_LOCATION + } } function _checkTryMulticallCaller() internal view virtual; diff --git a/test/SignedProposer.t.sol b/test/SignedProposer.t.sol index 570ccf7..12a9e6f 100644 --- a/test/SignedProposer.t.sol +++ b/test/SignedProposer.t.sol @@ -320,6 +320,19 @@ contract SignedProposerTest is Test { if (outerSuccess) successes = abi.decode(returnData, (bool[])); } + function test_tryMulticall_usesDerivedStorageNamespace() public { + bytes32 location = + keccak256(abi.encode(uint256(keccak256("uma.storage.TryMulticall")) - 1)) & ~bytes32(uint256(0xff)); + vm.store(address(signedProposer), location, bytes32(uint256(1))); + vm.expectRevert(TryMulticall.TryMulticallReentrantCall.selector); + vm.prank(relayer); + signedProposer.tryMulticall(new bytes[](0)); + + vm.store(address(signedProposer), location, bytes32(0)); + vm.prank(relayer); + assertEq(signedProposer.tryMulticall(new bytes[](0)).length, 0); + } + // ─── Propose tests ────────────────────────────────────────────────────────── function test_propose() public {