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
16 changes: 13 additions & 3 deletions script/DeploySignedProposer.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.27;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
Expand All @@ -9,7 +10,7 @@ import {SignedProposer} from "../src/optimistic-oracle-v2/implementation/SignedP

/**
* @title Deployment script for SignedProposer
* @notice Deploys SignedProposer with configurable Permit2 and admin addresses
* @notice Deploys a UUPS SignedProposer implementation and atomically initialized ERC1967 proxy
*
* Environment variables:
* - MNEMONIC: Required. The mnemonic phrase for the deployer wallet
Expand All @@ -33,12 +34,21 @@ contract DeploySignedProposer is Script {

vm.startBroadcast(deployerPrivateKey);

signedProposer = new SignedProposer(ISignatureTransfer(permit2Address), admin);
SignedProposer implementation = new SignedProposer();
signedProposer = SignedProposer(
address(
new ERC1967Proxy(
address(implementation),
abi.encodeCall(SignedProposer.initialize, (ISignatureTransfer(permit2Address), admin))
)
)
);

vm.stopBroadcast();

console.log("\n=== Deployment Summary ===");
console.log("SignedProposer:", address(signedProposer));
console.log("SignedProposer proxy:", address(signedProposer));
console.log("SignedProposer implementation:", address(implementation));
console.log("Chain ID:", block.chainid);
console.log("Deployer:", deployer);
console.log("Permit2:", permit2Address);
Expand Down
70 changes: 66 additions & 4 deletions script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,90 @@ The `ManagedOptimisticOracleV2` contract:

## SignedProposer Deployment

The `DeploySignedProposer.s.sol` script deploys `SignedProposer` using the canonical Permit2 deployment by default.
The `DeploySignedProposer.s.sol` script deploys a UUPS `SignedProposer` implementation and an ERC1967 proxy, atomically calling `initialize(permit2, admin)` during proxy construction. It uses the canonical Permit2 deployment by default and logs both addresses. The implementation disables initialization.

### Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `MNEMONIC` | Yes | The mnemonic phrase for the deployer wallet (uses 0 index address) |
| `PERMIT2_ADDRESS` | No | Permit2 address; defaults to `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
| `SIGNED_PROPOSER_ADMIN` | No | Address receiving the default admin role; defaults to the deployer |
| `SIGNED_PROPOSER_ADMIN` | No | Address receiving the default admin role, including upgrade authority; defaults to the deployer |

### Usage

```bash
forge script script/DeploySignedProposer.s.sol --rpc-url "YOUR_RPC_URL" --broadcast
```

The script only deploys the contract. The admin configures delegated proposers and any required whitelist ownership separately.
The script deploys and initializes the proxy. The admin configures delegated proposers and any required whitelist ownership separately. Use the **proxy address** for all relay calls, the Permit2 spender in signatures, whitelist membership, and whitelist ownership.

### Upgradeability

SignedProposer uses the same OpenZeppelin UUPS/ERC1967 mechanism as Managed OO and OOReporter. Its existing `DEFAULT_ADMIN_ROLE` authorizes `upgradeToAndCall(newImplementation, data)` on the proxy; no separate owner, proxy admin contract, or upgrade role is added. Delegated proposers and whitelist admins cannot upgrade unless they also hold the default admin role. Use empty `data` when no migration is needed; do not call `initialize` again.

The Permit2 address is initialized in proxy storage. Roles, retained token balances, whitelist ownership, and the Permit2 spender address survive compatible implementation upgrades. Existing signatures remain usable subject to their original deadlines, nonce usage, and proposal validity. The default admin is trusted to install implementations that can change relay behavior, including how outstanding signatures are handled.

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
`tryMulticall(bytes[])`. There is no contract-level batch-size or per-child gas limit; transaction
calldata, client transaction-pool policy, and available block gas provide the practical bounds.
Each valid child executes by self-delegatecall with the original relayer as `msg.sender`. A child
revert does not roll back successful siblings if the outer call retains enough gas to finish. Under
EIP-150, a gas-exhausting child can return `false` while preserving 1/64 of the caller's gas, so the
outer call may continue; however, later children can then be gas-starved and also return `false`.
If the remaining outer gas is insufficient to finish the loop or encode the result, the entire
batch reverts and rolls back earlier successes.

Polygon Bor rejects transactions larger than 128 KiB. With the maximum valid OOv2 ancillary data
of 8,139 non-zero bytes, each encoded `propose` child is 8,804 bytes: 14 children produce 124,612
bytes of outer calldata; the proxy-based capacity test uses the 53,902,641 gas limit at pinned block `81,683,818`,
while 15 children produce 133,508 bytes before the signed transaction envelope and are rejected.
Smaller ancillary data permits larger batches, subject to the same transaction-size and gas bounds.

The function returns a `bool[]` aligned with the submitted calls. A failed child also emits:

```solidity
event ProposalCallFailed(
uint256 indexed index,
bytes32 indexed callHash,
bytes4 errorSelector,
bytes32 revertDataHash
);
```

`callHash` is `keccak256(calls[index])`, `errorSelector` is the first four revert-data bytes (or
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.
In particular, empty failure metadata is ambiguous between an empty revert and out-of-gas.

OpenZeppelin `multicall(bytes[])` remains available and atomic for compatibility. It deliberately accepts any caller
and selector: self-delegatecall preserves the original caller, and each called function enforces its own permissions.
It has no batch-level reentrancy guard; individual functions must apply any required protection. Future externally
reachable functions must retain their own authorization because `multicall` does not impose the delegated-proposer,
`propose`-only, or nesting restrictions of `tryMulticall`.

`tryMulticall` does not change worker behavior; worker integration must be performed separately.

### Verification

Verify the implementation with no constructor arguments. Verify the ERC1967 proxy separately using its implementation address and encoded `initialize(permit2, admin)` calldata as constructor arguments.

```bash
forge verify-contract <SIGNED_PROPOSER_ADDRESS> src/optimistic-oracle-v2/implementation/SignedProposer.sol:SignedProposer --chain-id <CHAIN_ID> --constructor-args $(cast abi-encode "constructor(address,address)" <PERMIT2_ADDRESS> <SIGNED_PROPOSER_ADMIN>) --etherscan-api-key <YOUR_ETHERSCAN_API_KEY>
forge verify-contract <SIGNED_PROPOSER_IMPLEMENTATION_ADDRESS> src/optimistic-oracle-v2/implementation/SignedProposer.sol:SignedProposer --chain-id <CHAIN_ID> --etherscan-api-key <YOUR_ETHERSCAN_API_KEY>
```

## ManagedOptimisticOracleV2 Upgrade
Expand Down
89 changes: 89 additions & 0 deletions src/common/implementation/TryMulticall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.27;

/**
* @title TryMulticall
* @notice Executes allowed self-delegatecalls without reverting successful siblings.
* @custom:security-contact bugs@umaproject.org
*/
abstract contract TryMulticall {
/// @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
/// 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. 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.
*/
function tryMulticall(bytes[] calldata calls) external returns (bool[] memory successes) {
_checkTryMulticallCaller();
TryMulticallStorage storage $ = _getTryMulticallStorage();
if ($.entered) revert TryMulticallReentrantCall();

uint256 callsLength = calls.length;
bytes4 allowedSelector = _tryMulticallSelector();
for (uint256 i; i < callsLength; ++i) {
bytes calldata callData = calls[i];
bytes4 selector = callData.length >= 4 ? bytes4(callData[:4]) : bytes4(0);
if (selector != allowedSelector) revert TryMulticallInvalidSelector(i, selector);
}

successes = new bool[](callsLength);
$.entered = true;
for (uint256 i; i < callsLength; ++i) {
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) {
emit ProposalCallFailed(i, keccak256(callData), errorSelector, revertDataHash);
}
}
$.entered = false;
}

function _getTryMulticallStorage() private pure returns (TryMulticallStorage storage $) {
assembly {
$.slot := TRY_MULTICALL_STORAGE_LOCATION
}
}

function _checkTryMulticallCaller() internal view virtual;

function _tryMulticallSelector() internal view virtual returns (bytes4);
}
Loading
Loading