diff --git a/script/README.md b/script/README.md index 65d79ef..a96e1b6 100644 --- a/script/README.md +++ b/script/README.md @@ -333,6 +333,12 @@ The Permit2 address is initialized in proxy storage. Roles, retained token balan Future upgrades must preserve the storage layout, including the inherited `TryMulticall` batch lock and `permit2`, and retain the UUPS authorization hook. Validate storage compatibility against the deployed build before upgrading. This deployment change does not retrofit upgradeability onto any previously deployed direct SignedProposer instance; that requires a new proxy deployment and updating integrations to its address. +The integrated layout stores the batch lock in the ERC-7201 namespace `uma.storage.TryMulticall` and `permit2` at +slot 0, offset 0. This is the layout for the initial proxy deployment. The earlier UUPS proposal with a sequential batch +lock placed `permit2` at slot 0, offset 1; it is not storage-compatible with this version. Do not upgrade a proxy using +that earlier layout directly to this implementation. Such a deployment requires a separately reviewed migration or a +new proxy. The integration does not include a storage migration. + ### Partial-success proposal batches Delegated proposers can submit ABI-encoded `SignedProposer.propose` calls through diff --git a/script/reporters/UpgradeOOReporter.s.sol b/script/reporters/UpgradeOOReporter.s.sol index 95cfbaa..9cf5e77 100644 --- a/script/reporters/UpgradeOOReporter.s.sol +++ b/script/reporters/UpgradeOOReporter.s.sol @@ -408,7 +408,7 @@ contract UpgradeOOReporter is Script { Vm.EthGetLogs memory requestLog, address expectedRequester, uint256 logIndex - ) private view returns (bytes32 requestId) { + ) internal view returns (bytes32 requestId) { if (requestLog.removed || requestLog.topics.length != 4 || requestLog.topics[0] != REQUEST_REGISTERED_TOPIC) { revert InvalidRegisteredRequestLog(logIndex); } @@ -418,13 +418,13 @@ contract UpgradeOOReporter is Script { bytes32 priceIdentifier = requestLog.topics[3]; (bytes memory requestRules, uint64 minimumLiveness, uint64 maximumLiveness) = abi.decode(requestLog.data, (bytes, uint64, uint64)); + // Registered aliases resolve to canonical state; the reverse lookup need not equal this log's request ID. RequestData memory request = reporter.getRequest(requestId); if ( !request.registered || requester != expectedRequester || request.requester != requester || request.priceIdentifier != priceIdentifier || keccak256(request.requestRules) != keccak256(requestRules) || request.minimumLiveness != minimumLiveness || request.maximumLiveness != maximumLiveness - || reporter.getRequestId(priceIdentifier, requestRules) != requestId ) revert RegisteredRequestStateMismatch(requestId); } @@ -509,7 +509,7 @@ contract UpgradeOOReporter is Script { } function _snapshotReporterState(OOReporter reporter, Config memory config, bytes32[] memory requestIds) - private + internal view returns (ReporterState memory state) { @@ -549,7 +549,7 @@ contract UpgradeOOReporter is Script { ReporterState memory expectedState, bytes32[] memory requestIds, address finalImplementation - ) private view { + ) internal view { _expectAddress("final reporter implementation", finalImplementation, _getImplementation(address(reporter))); _expectAddress( "current Managed OO implementation", @@ -571,10 +571,9 @@ contract UpgradeOOReporter is Script { for (uint256 i = 0; i < requestIds.length; i++) { RequestData memory request = reporter.getRequest(requestIds[i]); - if ( - keccak256(abi.encode(request)) != expectedState.requestHashes[i] - || reporter.getRequestId(request.priceIdentifier, request.requestRules) != requestIds[i] - ) revert RequestStateChanged(requestIds[i]); + if (keccak256(abi.encode(request)) != expectedState.requestHashes[i]) { + revert RequestStateChanged(requestIds[i]); + } } _validateExternalWiring(config); diff --git a/src/reporters/OOReporter.sol b/src/reporters/OOReporter.sol index 8e94422..4c25fb3 100644 --- a/src/reporters/OOReporter.sol +++ b/src/reporters/OOReporter.sol @@ -684,7 +684,8 @@ contract OOReporter is emit RequestRerequestAllowed(requestId, requestTimestamp, trigger); } - /// @dev Returns the canonical request ID shared by requestId and any duplicate registrations, or reverts for unregistered IDs. + /// @dev Returns the canonical request ID shared by requestId and any duplicate registrations, or reverts for + /// unregistered IDs. function _canonicalRequestId(bytes32 requestId) private view returns (bytes32 canonicalRequestId) { OOReporterStorage storage $ = _getStorage(); RequestData storage registration = $.requests[requestId]; diff --git a/src/reporters/README.md b/src/reporters/README.md index 9c12ce3..b6a7c1e 100644 --- a/src/reporters/README.md +++ b/src/reporters/README.md @@ -447,8 +447,9 @@ its requester whitelist, and the downstream module wiring before deploying anyth | `EXPECTED_STATE_FINGERPRINT` | Required in verify mode. Copy the fingerprint printed by the final pre-upgrade run. | The script derives the complete request-ID list from `RequestRegistered` logs instead of accepting a hand-curated list. -For every event it validates the requester, identifier, rules, liveness range, and tuple lookup against current proxy -storage, then snapshots the full stored request for the post-upgrade comparison. Log queries are split into configurable +For every event it validates the requester, identifier, rules, and liveness range against `getRequest(requestId)`, then +snapshots that canonical request state for the post-upgrade comparison. A registered alias is valid even when the +tuple's canonical ID differs from the ID in the event. Log queries are split into configurable block ranges for RPC compatibility. The script also reconstructs requester and oracle-initializer allowlist state from events and requires the expected module and initializer to be the only enabled accounts. Active requests are safe because the Managed OO address does not change. Quiesce every reporter mutation from @@ -517,8 +518,8 @@ forge script script/reporters/UpgradeOOReporter.s.sol:UpgradeOOReporter \ After either EOA or Safe execution, set `VERIFY_ONLY=true`, set `FINAL_IMPLEMENTATION`, its code hash, and `EXPECTED_STATE_FINGERPRINT` from the final pre-upgrade run, then run the script without `--broadcast`. This live, rerunnable verification checks the exact final implementation; unchanged Managed OO implementation, Initializable slot, -owner, reward currency, re-request configuration, requester and initializer access; byte-for-byte ABI encoding and tuple -lookup of every registered request; zero `pendingOwner`; Managed OO whitelist acceptance; and the module proxy, +owner, reward currency, re-request configuration, requester and initializer access; byte-for-byte ABI encoding of the +canonical state returned for every registered request ID; zero `pendingOwner`; Managed OO whitelist acceptance; and the module proxy, implementation, and reporter pointer. The immediate checks in Forge's broadcast simulation are not a substitute for this post-broadcast run. diff --git a/test/SignedProposer.t.sol b/test/SignedProposer.t.sol index 4db7008..31b0d01 100644 --- a/test/SignedProposer.t.sol +++ b/test/SignedProposer.t.sol @@ -987,7 +987,8 @@ contract SignedProposerTest is Test { 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); + // The self-delegatecall also traverses the proxy, which must copy the child's revert payload before the cap. + (bool outerSuccess, bool[] memory successes) = _tryMulticallWithGas(calls, 2_800_000); assertTrue(outerSuccess); assertTrue(successes[0]); diff --git a/test/reporters/UpgradeOOReporterScript.t.sol b/test/reporters/UpgradeOOReporterScript.t.sol new file mode 100644 index 0000000..2f9a76d --- /dev/null +++ b/test/reporters/UpgradeOOReporterScript.t.sol @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.30; + +import {Test} from "forge-std/Test.sol"; +import {Vm} from "forge-std/Vm.sol"; +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {OOReporter} from "src/reporters/OOReporter.sol"; +import {IOOReporter} from "src/reporters/interfaces/IOOReporter.sol"; +import {PolymarketOOReporter} from "src/reporters/integrations/PolymarketOOReporter.sol"; +import {UpgradeOOReporter} from "script/reporters/UpgradeOOReporter.s.sol"; +import {MockERC20} from "test/reporters/mocks/MockERC20.sol"; +import {MockOptimisticOracleV2} from "test/reporters/mocks/MockOptimisticOracleV2.sol"; +import {AddressWhitelist} from "src/common/implementation/AddressWhitelist.sol"; + +contract UpgradeScriptOracle is MockOptimisticOracleV2 { + address public immutable requesterWhitelist; + + constructor(address whitelist) { + requesterWhitelist = whitelist; + } +} + +contract UpgradeOOReporterHarness is UpgradeOOReporter { + function validateRegistration(OOReporter reporter, Vm.EthGetLogs memory requestLog, address requester) + external + view + returns (bytes32) + { + return _validateRegisteredRequest(reporter, requestLog, requester, 0); + } + + function snapshot(OOReporter reporter, Config memory config, bytes32[] memory requestIds) + external + view + returns (ReporterState memory) + { + return _snapshotReporterState(reporter, config, requestIds); + } + + function validatePostUpgrade( + OOReporter reporter, + Config memory config, + ReporterState memory expectedState, + bytes32[] memory requestIds, + address implementation + ) external view { + _validatePostUpgrade(reporter, config, expectedState, requestIds, implementation); + } +} + +contract UpgradeOOReporterScriptTest is Test { + OOReporter public ooReporter; + + function test_registrationValidationAcceptsAliasesAcrossUpgradeAndRejectsMismatchedLogs() public { + AddressWhitelist whitelist = new AddressWhitelist(); + UpgradeScriptOracle oracle = new UpgradeScriptOracle(address(whitelist)); + MockERC20 currency = new MockERC20(); + OOReporter reporter = OOReporter( + address( + new ERC1967Proxy( + address(new PolymarketOOReporter()), + abi.encodeCall( + IOOReporter.initialize, + (address(this), address(oracle), address(currency), address(this), address(this), 5) + ) + ) + ) + ); + ooReporter = reporter; + whitelist.addToWhitelist(address(reporter)); + UpgradeOOReporterHarness script = new UpgradeOOReporterHarness(); + bytes32 canonicalId = keccak256("canonical"); + bytes32 aliasId = keccak256("alias"); + bytes32 identifier = "YES_OR_NO_QUERY"; + bytes memory rules = bytes("shared rules"); + + vm.recordLogs(); + reporter.registerRequest(canonicalId, identifier, rules, 0, 2 days); + reporter.registerRequest(aliasId, identifier, rules, 0, 2 days); + Vm.Log[] memory logs = vm.getRecordedLogs(); + assertEq(logs.length, 2); + assertEq(reporter.getRequestId(identifier, rules), canonicalId); + + UpgradeOOReporter.Config memory config; + config.proxy = address(reporter); + config.expectedCurrentOptimisticOracle = address(oracle); + config.expectedMooRequesterWhitelist = address(whitelist); + config.expectedRequester = address(this); + config.expectedOracleInitializer = address(this); + bytes32[] memory requestIds = new bytes32[](2); + requestIds[0] = canonicalId; + requestIds[1] = aliasId; + UpgradeOOReporter.ReporterState memory stateBefore = script.snapshot(reporter, config, requestIds); + address finalImplementation = address(new PolymarketOOReporter()); + + for (uint256 pass; pass < 2; ++pass) { + if (pass == 1) { + reporter.upgradeToAndCall(finalImplementation, ""); + script.validatePostUpgrade(reporter, config, stateBefore, requestIds, finalImplementation); + } + for (uint256 i; i < logs.length; ++i) { + Vm.EthGetLogs memory requestLog; + requestLog.emitter = logs[i].emitter; + requestLog.topics = logs[i].topics; + requestLog.data = logs[i].data; + assertEq( + script.validateRegistration(reporter, requestLog, address(this)), i == 0 ? canonicalId : aliasId + ); + + requestLog.data = abi.encode(bytes("different rules"), uint64(0), uint64(2 days)); + vm.expectRevert( + abi.encodeWithSelector( + UpgradeOOReporter.RegisteredRequestStateMismatch.selector, requestLog.topics[1] + ) + ); + script.validateRegistration(reporter, requestLog, address(this)); + } + } + + reporter.initializeRequest(aliasId, 0, 0, 2 hours); + vm.expectRevert(abi.encodeWithSelector(UpgradeOOReporter.RequestStateChanged.selector, canonicalId)); + script.validatePostUpgrade(reporter, config, stateBefore, requestIds, finalImplementation); + } +}