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
5 changes: 3 additions & 2 deletions script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ event ProposalCallFailed(
```

`callHash` is `keccak256(calls[index])`, `errorSelector` is the first four revert-data bytes (or
zero when unavailable), and `revertDataHash` hashes the complete revert data. Full proposal
calldata, signatures, and revert data are never logged. Successful children continue to emit the
zero when unavailable), and `revertDataHash` hashes at most the first 256 revert-data bytes. The
batch copies only that bounded prefix before hashing. Full proposal calldata, signatures, and
revert data are never logged. Successful children continue to emit the
existing `ProposalExecuted` and oracle `ProposePrice` events. Consumers should use those events as
the authoritative success evidence. A `false` result and `ProposalCallFailed` mean only that the
execution attempt did not complete successfully; they do not prove the proposal itself is invalid.
Expand Down
27 changes: 21 additions & 6 deletions src/common/implementation/TryMulticall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ abstract contract TryMulticall {
/// @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
/// the submitted operation itself is invalid; callers may retry it with a different gas allocation.
/// `revertDataHash` hashes at most the first 256 bytes of revert data; larger payloads are truncated before hashing.
event ProposalCallFailed(
uint256 indexed index, bytes32 indexed callHash, bytes4 errorSelector, bytes32 revertDataHash
);

error TryMulticallReentrantCall();
error TryMulticallInvalidSelector(uint256 index, bytes4 selector);

uint256 private constant MAX_REVERT_DATA_SIZE = 256;

/**
* @notice Executes allowed calls independently and returns their execution-attempt success values.
* @dev Self-delegatecall preserves the original caller. Ordinary failures emit only bounded metadata. There is no
* child gas or revert-data cap. Under EIP-150, an out-of-gas child can return `false` while leaving the outer call
* @dev Self-delegatecall preserves the original caller. Failed calls copy and hash at most 256 bytes of revert
* data. There is no child gas cap. Under EIP-150, an out-of-gas child can return `false` while leaving the outer call
* enough gas to continue, but later children may receive too little gas and also return `false`. If the remaining
* outer gas cannot finish the loop or encode the result, the full batch reverts. A `false` value therefore means
* only that the corresponding execution attempt failed; it does not prove the submitted operation is invalid.
Expand All @@ -41,13 +44,25 @@ abstract contract TryMulticall {
successes = new bool[](callsLength);
_tryMulticallEntered = true;
for (uint256 i; i < callsLength; ++i) {
bytes calldata callData = calls[i];
(bool success, bytes memory revertData) = address(this).delegatecall(callData);
bytes memory callData = calls[i];
bool success;
bytes4 errorSelector;
bytes32 revertDataHash;
assembly ("memory-safe") {
success := delegatecall(gas(), address(), add(callData, 0x20), mload(callData), 0, 0)
if iszero(success) {
let size := returndatasize()
if gt(size, MAX_REVERT_DATA_SIZE) { size := MAX_REVERT_DATA_SIZE }
let data := mload(0x40)
returndatacopy(data, 0, size)
if iszero(lt(size, 4)) { errorSelector := mload(data) }
revertDataHash := keccak256(data, size)
}
}
successes[i] = success;

if (!success) {
bytes4 errorSelector = revertData.length >= 4 ? bytes4(revertData) : bytes4(0);
emit ProposalCallFailed(i, keccak256(callData), errorSelector, keccak256(revertData));
emit ProposalCallFailed(i, keccak256(callData), errorSelector, revertDataHash);
}
}
_tryMulticallEntered = false;
Expand Down
41 changes: 39 additions & 2 deletions test/SignedProposer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ contract SignedProposerTest is Test {
assertEq(currency.balanceOf(proposer), 0);
}

function test_tryMulticall_hashesCompleteLargeRevertData() public {
function test_tryMulticall_hashesBoundedLargeRevertData() public {
uint256 timestamp = block.timestamp;
_makeRequest(timestamp, 0);
_setBond();
Expand All @@ -853,8 +853,12 @@ contract SignedProposerTest is Test {
calls[0] = _encodeProposalCall(failedProposal, proposer, permit, "", 0);
calls[1] = _encodeProposalCall(validProposal, proposer, permit, "", 0);

bytes memory expectedPrefix = new bytes(256);
for (uint256 i; i < expectedPrefix.length; ++i) {
expectedPrefix[i] = bytes1(uint8(i % 251 + 1));
}
vm.expectEmit(true, true, false, true, address(signedProposer));
emit ProposalCallFailed(0, keccak256(calls[0]), bytes4(0), keccak256(new bytes(revertDataSize)));
emit ProposalCallFailed(0, keccak256(calls[0]), bytes4(0x01020304), keccak256(expectedPrefix));

vm.prank(relayer);
bool[] memory successes = signedProposer.tryMulticall(calls);
Expand All @@ -863,6 +867,35 @@ contract SignedProposerTest is Test {
assertTrue(successes[1]);
}

function test_tryMulticall_largeRevertPreservesEarlierSuccessWithLimitedGas() public {
uint256 timestamp = block.timestamp;
_makeRequest(timestamp, 0);
_setBond();
_fundAndApproveProposer(TOTAL_BOND);

SignedProposer.Proposal memory validProposal = _buildProposal(timestamp, 2 ether);
SignedProposer.Proposal memory failedProposal = _buildRevertingProposal(false, 512 * 1024, timestamp, 1 ether);
ISignatureTransfer.PermitTransferFrom memory permit = _buildPermit(TOTAL_BOND, 0, block.timestamp + 1 hours);
bytes[] memory calls = new bytes[](2);
calls[0] = _encodeProposalCall(validProposal, proposer, permit, "", 0);
calls[1] = _encodeProposalCall(failedProposal, proposer, permit, "", 0);

bytes memory expectedPrefix = new bytes(256);
for (uint256 i; i < expectedPrefix.length; ++i) {
expectedPrefix[i] = bytes1(uint8(i % 251 + 1));
}
vm.expectEmit(true, true, false, true, address(signedProposer));
emit ProposalCallFailed(1, keccak256(calls[1]), bytes4(0x01020304), keccak256(expectedPrefix));

(bool outerSuccess, bool[] memory successes) = _tryMulticallWithGas(calls, 2_000_000);

assertTrue(outerSuccess);
assertTrue(successes[0]);
assertFalse(successes[1]);
assertEq(moo.getRequest(requester, IDENTIFIER, timestamp, ANCILLARY).proposedPrice, 2 ether);
assertEq(currency.balanceOf(proposer), 0);
}

// ─── Delegated proposer role tests ───────────────────────────────────────────

function test_revert_propose_notDelegatedProposer() public {
Expand Down Expand Up @@ -1560,6 +1593,10 @@ contract RevertingSignedProposerOracle {
}

bytes memory revertData = new bytes(revertDataSize);
// Pattern the prefix and bytes beyond the cap without exhausting the gas-limited returndata regression.
for (uint256 i; i < revertData.length && i < 512; ++i) {
revertData[i] = bytes1(uint8(i % 251 + 1));
}
assembly ("memory-safe") {
revert(add(revertData, 0x20), mload(revertData))
}
Expand Down
Loading