Skip to content
Verified contractExactMIT

MessageRouterCacheResizer

Address0x8af32369e988ca264a53fac33e836a16651f5181
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 5 runs
EVM version
prague
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,457,111
Creation transaction
0x141b95ab5a…787b3f38c8

script/configure/utils/MessageRouterCacheResizer.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

/// @notice One-shot implementation that raises MessageRouter's send-cache size, which has no setter.
/// @dev Meant to be used only inside a single Safe batch on the router's ProxyAdmin:
///        1. upgradeAndCall(router, resizer, setMaxCacheSize(n))
///        2. upgradeAndCall(router, <original implementation>, "")
///      so the router never stays on this code. It writes one word of MessageRouter storage:
///      `_sendMessagesCache` is the RingCache at slot 3 — indices (3), ring (4), head (5), maxCacheSize (6),
///      id (7) — and the id word is checked first so a layout mismatch reverts instead of corrupting storage.
///      Growing the ring is safe mid-stream: entries keep their index, and `add` takes the size from storage.
contract MessageRouterCacheResizer {
    uint256 internal constant MAX_CACHE_SIZE_SLOT = 6;
    uint256 internal constant CACHE_ID_SLOT = 7;
    bytes32 internal constant SEND_CACHE_ID = keccak256("SEND_CACHE");
    /// @dev RingCacheLib.MAX_CACHE_SIZE; sizes must stay strictly below it.
    uint256 internal constant MAX_CACHE_SIZE = 256;
    /// @dev ERC-1967 admin slot: the ProxyAdmin that runs upgradeAndCall.
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    address private immutable SELF = address(this);

    event MaxCacheSizeUpdated(uint256 previousSize, uint256 newSize);

    function setMaxCacheSize(uint256 newSize) external {
        require(address(this) != SELF, "delegatecall only");

        address admin;
        bytes32 id;
        uint256 currentSize;
        assembly {
            admin := sload(ADMIN_SLOT)
            id := sload(CACHE_ID_SLOT)
            currentSize := sload(MAX_CACHE_SIZE_SLOT)
        }
        require(msg.sender == admin, "only proxy admin");
        require(id == SEND_CACHE_ID, "storage layout mismatch");
        require(newSize > currentSize && newSize < MAX_CACHE_SIZE, "invalid size");

        assembly {
            sstore(MAX_CACHE_SIZE_SLOT, newSize)
        }
        emit MaxCacheSizeUpdated(currentSize, newSize);
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 5,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@shift-defi/cow-protocol-adapter/=node_modules/@shift-defi/cow-protocol-adapter/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/",
    "lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-foundry-upgrades/:forge-std/=lib/openzeppelin-foundry-upgrades/lib/forge-std/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.