From 71d608ec6da143d3959780c545830bcfb6870622 Mon Sep 17 00:00:00 2001 From: Pablo Maldonado Date: Mon, 14 Sep 2026 09:39:48 +0100 Subject: [PATCH 1/2] fix: bound batch failure revert data --- script/README.md | 5 ++-- src/common/implementation/TryMulticall.sol | 27 +++++++++++++++----- test/SignedProposer.t.sol | 29 ++++++++++++++++++++-- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/script/README.md b/script/README.md index ca5c3e3..828b72e 100644 --- a/script/README.md +++ b/script/README.md @@ -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. diff --git a/src/common/implementation/TryMulticall.sol b/src/common/implementation/TryMulticall.sol index f7cd4eb..9eb3504 100644 --- a/src/common/implementation/TryMulticall.sol +++ b/src/common/implementation/TryMulticall.sol @@ -11,6 +11,7 @@ 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 ); @@ -18,10 +19,12 @@ abstract contract TryMulticall { 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. @@ -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; diff --git a/test/SignedProposer.t.sol b/test/SignedProposer.t.sol index 570ccf7..f7bcc60 100644 --- a/test/SignedProposer.t.sol +++ b/test/SignedProposer.t.sol @@ -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(); @@ -854,7 +854,7 @@ contract SignedProposerTest is Test { calls[1] = _encodeProposalCall(validProposal, proposer, permit, "", 0); 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(0), keccak256(new bytes(256))); vm.prank(relayer); bool[] memory successes = signedProposer.tryMulticall(calls); @@ -863,6 +863,31 @@ 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); + + vm.expectEmit(true, true, false, true, address(signedProposer)); + emit ProposalCallFailed(1, keccak256(calls[1]), bytes4(0), keccak256(new bytes(256))); + + (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 { From da6cb0d140484100acefea14b84fbebdc5338561 Mon Sep 17 00:00:00 2001 From: Pablo Maldonado Date: Mon, 14 Sep 2026 15:06:45 +0100 Subject: [PATCH 2/2] test: verify nonzero revert data prefix hashes --- test/SignedProposer.t.sol | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/SignedProposer.t.sol b/test/SignedProposer.t.sol index f7bcc60..8750b71 100644 --- a/test/SignedProposer.t.sol +++ b/test/SignedProposer.t.sol @@ -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(256))); + emit ProposalCallFailed(0, keccak256(calls[0]), bytes4(0x01020304), keccak256(expectedPrefix)); vm.prank(relayer); bool[] memory successes = signedProposer.tryMulticall(calls); @@ -876,8 +880,12 @@ contract SignedProposerTest is Test { 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(0), keccak256(new bytes(256))); + emit ProposalCallFailed(1, keccak256(calls[1]), bytes4(0x01020304), keccak256(expectedPrefix)); (bool outerSuccess, bool[] memory successes) = _tryMulticallWithGas(calls, 2_000_000); @@ -1585,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)) }