Skip to content
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
22 changes: 18 additions & 4 deletions src/common/implementation/TryMulticall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Comment thread
md0x marked this conversation as resolved.
Resolved
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
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/SignedProposer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading