Skip to content
Verified contractPartialLicenseRef-DCL-1.0

Extrospect

Address0x01a8116e07d63348c02818af858769eacdaf134a
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.25

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.25+commit.b61c2a91
Language
solidity
Optimization
Yes, 100,000 runs
EVM version
cancun
License
LicenseRef-DCL-1.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,250,616
Creation transaction
0x54bb2a1c5c…9b378fd26a

src/concrete/Extrospect.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity =0.8.25;

import {IExtrospectV1} from "rain-extrospection-0.1.14/src/interface/IExtrospectV1.sol";
import {LibExtrospectBytecode} from "rain-extrospection-0.1.14/src/lib/LibExtrospectBytecode.sol";
import {LibExtrospectMetamorphic} from "rain-extrospection-0.1.14/src/lib/LibExtrospectMetamorphic.sol";
import {LibExtrospectERC1167Proxy} from "rain-extrospection-0.1.14/src/lib/LibExtrospectERC1167Proxy.sol";
import {LibExtrospectERC1967BeaconProxy} from "rain-extrospection-0.1.14/src/lib/LibExtrospectERC1967BeaconProxy.sol";

/// @title Extrospect
/// @notice Concrete implementation of `IExtrospectV1`. Parameterless
/// constructor for deterministic Zoltu deployment across EVM networks.
/// Consumers should depend on `IExtrospectV1` rather than importing this
/// contract directly.
contract Extrospect is IExtrospectV1 {
    /// @inheritdoc IExtrospectV1
    function checkCBORTrimmedBytecodeHash(address account, bytes32 expected) external view {
        LibExtrospectBytecode.checkCBORTrimmedBytecodeHash(account, expected);
    }

    /// @inheritdoc IExtrospectV1
    function checkNoSolidityCBORMetadata(address account) external view {
        LibExtrospectBytecode.checkNoSolidityCBORMetadata(account);
    }

    /// @inheritdoc IExtrospectV1
    function checkNotEOFBytecode(bytes memory bytecode) external pure {
        LibExtrospectBytecode.checkNotEOFBytecode(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function checkNotMetamorphic(bytes memory bytecode) external pure {
        LibExtrospectMetamorphic.checkNotMetamorphic(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function isBeaconImplementationBytecode(address beacon, bytes32 expectedRuntimeHash) external view returns (bool) {
        return LibExtrospectERC1967BeaconProxy.isBeaconImplementationBytecode(beacon, expectedRuntimeHash);
    }

    /// @inheritdoc IExtrospectV1
    function isBeaconOwner(address beacon, address expectedOwner) external view returns (bool) {
        return LibExtrospectERC1967BeaconProxy.isBeaconOwner(beacon, expectedOwner);
    }

    /// @inheritdoc IExtrospectV1
    function isEOFBytecode(bytes memory bytecode) external pure returns (bool) {
        return LibExtrospectBytecode.isEOFBytecode(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function isERC1167Proxy(bytes memory bytecode) external pure returns (bool, address) {
        // False positive: tuple pass-through — both components re-emitted as this
        // function's own return, nothing discarded.
        // slither-disable-next-line unused-return
        return LibExtrospectERC1167Proxy.isERC1167Proxy(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function scanEVMOpcodesPresentInBytecode(bytes memory bytecode) external pure returns (uint256) {
        return LibExtrospectBytecode.scanEVMOpcodesPresentInBytecode(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function scanEVMOpcodesReachableInBytecode(bytes memory bytecode) external pure returns (uint256) {
        return LibExtrospectBytecode.scanEVMOpcodesReachableInBytecode(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function scanMetamorphicRisk(bytes memory bytecode) external pure returns (uint256) {
        return LibExtrospectMetamorphic.scanMetamorphicRisk(bytecode);
    }

    /// @inheritdoc IExtrospectV1
    function tryTrimSolidityCBORMetadata(bytes memory bytecode)
        external
        pure
        returns (bool didTrim, bytes memory trimmedBytecode)
    {
        didTrim = LibExtrospectBytecode.tryTrimSolidityCBORMetadata(bytecode);
        return (didTrim, bytecode);
    }
}

dependencies/rain-extrospection-0.1.14/src/interface/IBeacon.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IBeacon
/// @notice De-facto interface every ERC-1967 beacon contract exposes so
/// the proxies routed through it can fetch the current implementation
/// each delegate call. Replicated from OpenZeppelin's `IBeacon` to keep
/// rain.extrospection callable without pulling the full OZ dependency
/// for one selector.
interface IBeacon {
    /// @notice The implementation contract the beacon currently points
    /// at. Beacon proxies route every delegate call through this getter.
    /// @return The implementation address.
    function implementation() external view returns (address);
}

dependencies/rain-extrospection-0.1.14/src/interface/IExtrospectV1.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IExtrospectV1
/// @notice External interface to the extrospection libraries. Every
/// function forwards to the library function it names. The concrete
/// implementation (`Extrospect`) and its deployment live in
/// rain.extrospection.deploy.
/// @dev The custom errors named below are declared by the libraries, not by
/// this interface. `EOFBytecodeNotSupported`, `MetadataNotTrimmed`,
/// `BytecodeHashMismatch`, `UnexpectedMetadata` and `CodelessAccount` come
/// from `LibExtrospectBytecode`; `Metamorphic` comes from
/// `LibExtrospectMetamorphic`.
interface IExtrospectV1 {
    /// @notice Reads `account`'s runtime bytecode, trims trailing Solidity CBOR
    /// metadata from it, and reverts unless what remains hashes to
    /// `expectedTrimmedHash`. Reverts `MetadataNotTrimmed` when the bytecode
    /// does not end in the exact metadata structure the trimmer recognises,
    /// so nothing was trimmed. Reverts
    /// `BytecodeHashMismatch(expectedTrimmedHash, actual)` when the trimmed
    /// bytecode hashes to something other than `expectedTrimmedHash`. Reverts
    /// `EOFBytecodeNotSupported` when `account`'s bytecode is EOF. Returns
    /// nothing when the hash matches.
    /// @dev See `LibExtrospectBytecode.checkCBORTrimmedBytecodeHash`.
    /// @param account The account whose runtime bytecode is read and checked.
    /// @param expectedTrimmedHash `keccak256` of the bytecode AFTER its last
    /// 53 bytes are removed, not of the full runtime bytecode. Not the same
    /// value as `isBeaconImplementationBytecode`'s `expectedRuntimeHash`,
    /// which hashes runtime bytecode whole.
    function checkCBORTrimmedBytecodeHash(address account, bytes32 expectedTrimmedHash) external view;

    /// @notice Reads `account`'s runtime bytecode and reverts
    /// `UnexpectedMetadata` when its last 53 bytes are the exact Solidity CBOR
    /// metadata structure `tryTrimSolidityCBORMetadata` recognises. Reverts
    /// `CodelessAccount(account)` when `account` has no code: absence of code
    /// is not absence of metadata risk, so the check refuses to vouch for a
    /// codeless account. Reverts `EOFBytecodeNotSupported` when `account`'s
    /// bytecode is EOF. Returns nothing when the account has code in which no
    /// such metadata is detected, including metadata in any other shape.
    /// @dev See `LibExtrospectBytecode.checkNoSolidityCBORMetadata`.
    /// @param account The account whose runtime bytecode is read and checked.
    function checkNoSolidityCBORMetadata(address account) external view;

    /// @notice Reverts `EOFBytecodeNotSupported` when `bytecode` begins with
    /// the EOF magic `0xEF00`. Returns nothing otherwise.
    /// @dev See `LibExtrospectBytecode.checkNotEOFBytecode`.
    /// @param bytecode The bytecode to check.
    function checkNotEOFBytecode(bytes memory bytecode) external pure;

    /// @notice Reverts `Metamorphic(riskyOpcodes)` when `scanMetamorphicRisk`
    /// reports a non-zero bitmap for `bytecode`, carrying that bitmap: any
    /// reachable metamorphic risk opcode, or a first byte of the EIP-3541
    /// reserved `0xEF` (an EOF container, an EIP-7702 delegation designator,
    /// or any future assignment of the prefix), which reverts
    /// `Metamorphic(1 << 0xEF)`. Never reverts `EOFBytecodeNotSupported`.
    /// Returns nothing when that bitmap is zero.
    /// @dev See `LibExtrospectMetamorphic.checkNotMetamorphic`.
    /// @param bytecode The bytecode to check.
    function checkNotMetamorphic(bytes memory bytecode) external pure;

    /// @notice Static-calls `implementation()` on `beacon` and hashes the
    /// runtime bytecode of the address it returns.
    /// @dev See `LibExtrospectERC1967BeaconProxy.isBeaconImplementationBytecode`.
    /// @param beacon The address to static-call `implementation()` on.
    /// @param expectedRuntimeHash `keccak256` of the implementation's runtime
    /// bytecode exactly as deployed, with no metadata trimming. Not the same
    /// value as `checkCBORTrimmedBytecodeHash`'s `expectedTrimmedHash`, which
    /// hashes runtime bytecode with its metadata trailer removed. For an
    /// implementation with no code this is `keccak256` of empty bytes.
    /// @return True when the static call succeeds, returns exactly 32 bytes
    /// whose top 12 bytes are zero, and the address in those bytes has runtime
    /// bytecode hashing to `expectedRuntimeHash`. False when the static call
    /// reverts, returns other than 32 bytes, or returns 32 bytes with any of
    /// the top 12 non-zero.
    function isBeaconImplementationBytecode(address beacon, bytes32 expectedRuntimeHash) external view returns (bool);

    /// @notice Static-calls `owner()` on `beacon` and compares the address it
    /// returns against `expectedOwner`.
    /// @dev See `LibExtrospectERC1967BeaconProxy.isBeaconOwner`.
    /// @param beacon The address to static-call `owner()` on.
    /// @param expectedOwner The address the call must return.
    /// @return True when the static call succeeds, returns exactly 32 bytes
    /// whose top 12 bytes are zero, and the address in those bytes equals
    /// `expectedOwner`. False when the static call reverts, returns other than
    /// 32 bytes, or returns 32 bytes with any of the top 12 non-zero.
    function isBeaconOwner(address beacon, address expectedOwner) external view returns (bool);

    /// @notice Whether `bytecode` begins with the EOF magic `0xEF00`. Never
    /// reverts. Bytecode shorter than 2 bytes is not EOF.
    /// @dev See `LibExtrospectBytecode.isEOFBytecode`.
    /// @param bytecode The bytecode to check.
    /// @return True when the first two bytes of `bytecode` are `0xEF00`.
    function isEOFBytecode(bytes memory bytecode) external pure returns (bool);

    /// @notice Whether `bytecode` is the 45 byte ERC-1167 minimal proxy, and
    /// the implementation address embedded in it when it is. Never reverts,
    /// and performs no EOF check.
    /// @dev See `LibExtrospectERC1167Proxy.isERC1167Proxy`.
    /// @param bytecode The bytecode to check.
    /// @return True when `bytecode` is exactly 45 bytes and carries the
    /// ERC-1167 prefix and suffix.
    /// @return The 20 bytes at offset 10 of `bytecode` read as an address, or
    /// the zero address when the first return is false.
    function isERC1167Proxy(bytes memory bytecode) external pure returns (bool, address);

    /// @notice Bitmap of every opcode byte a linear scan of `bytecode` reads,
    /// skipping the inline data of `PUSH*` opcodes. Regions that never execute,
    /// such as trailing metadata, still set bits. Reverts
    /// `EOFBytecodeNotSupported` when `bytecode` is EOF.
    /// @dev See `LibExtrospectBytecode.scanEVMOpcodesPresentInBytecode`.
    /// @param bytecode The bytecode to scan.
    /// @return A bitmap, not a count: bit `N` is set when opcode `N` was read.
    function scanEVMOpcodesPresentInBytecode(bytes memory bytecode) external pure returns (uint256);

    /// @notice Bitmap of the opcodes a linear scan of `bytecode` treats as
    /// reachable. The scan skips the inline data of `PUSH*` opcodes, pauses at
    /// each halting opcode (`STOP`, `JUMP`, `RETURN`, `REVERT`, `INVALID`,
    /// `SELFDESTRUCT`) and resumes at the next `JUMPDEST`, so bytes between a
    /// halt and the next `JUMPDEST` set no bits. Reachability is
    /// over-approximated: a `JUMPDEST` that no execution path can reach still
    /// resumes the scan. Reverts `EOFBytecodeNotSupported` when `bytecode` is
    /// EOF.
    /// @dev See `LibExtrospectBytecode.scanEVMOpcodesReachableInBytecode`.
    /// @param bytecode The bytecode to scan.
    /// @return A bitmap, not a count: bit `N` is set when opcode `N` was
    /// scanned as reachable.
    function scanEVMOpcodesReachableInBytecode(bytes memory bytecode) external pure returns (uint256);

    /// @notice Bitmap of the metamorphic risk opcodes
    /// (`SELFDESTRUCT`, `DELEGATECALL`, `CALLCODE`, `CREATE`, `CREATE2`) that
    /// `scanEVMOpcodesReachableInBytecode` finds reachable in `bytecode`.
    /// Bytecode whose first byte is the EIP-3541 reserved `0xEF` — an EOF
    /// container, an EIP-7702 delegation designator, or any future
    /// assignment of the prefix — fails closed to a bitmap of exactly
    /// `1 << 0xEF` instead of being scanned. Never reverts.
    /// @dev See `LibExtrospectMetamorphic.scanMetamorphicRisk`.
    /// @param bytecode The bytecode to scan.
    /// @return A bitmap, not a count or a score: bit `N` is set when
    /// metamorphic opcode `N` is reachable, and bit `0xEF` alone is set when
    /// the first byte is the reserved `0xEF`. Zero when neither holds.
    function scanMetamorphicRisk(bytes memory bytecode) external pure returns (uint256);

    /// @notice Removes the last 53 bytes of `bytecode` when they are the exact
    /// Solidity CBOR metadata structure the trimmer recognises. Metadata in any
    /// other shape is not trimmed and does not revert. Reverts
    /// `EOFBytecodeNotSupported` when `bytecode` is EOF.
    /// @dev See `LibExtrospectBytecode.tryTrimSolidityCBORMetadata`, which
    /// takes `bytes memory` and trims it in place. Across this external
    /// interface the argument arrives as a fresh copy decoded from calldata
    /// into the callee's memory, so the caller's own `bytecode` is untouched:
    /// the trim lands on that copy and the copy comes back as
    /// `trimmedBytecode`.
    /// @param bytecode The bytecode to trim.
    /// @return didTrim True when the last 53 bytes matched and were removed.
    /// @return trimmedBytecode `bytecode` less its last 53 bytes when `didTrim`
    /// is true, otherwise `bytecode` unchanged.
    function tryTrimSolidityCBORMetadata(bytes memory bytecode)
        external
        pure
        returns (bool didTrim, bytes memory trimmedBytecode);
}

dependencies/rain-extrospection-0.1.14/src/interface/IOwnable.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IOwnable
/// @notice Minimal owner getter, matching the `owner()` selector exposed
/// by OpenZeppelin's `Ownable` and ERC-5313 (Light Contract Ownership).
/// Replicated locally so callers can read a beacon's owner without
/// pulling in OZ's full Ownable contract just for one selector.
interface IOwnable {
    /// @notice The contract's current owner.
    /// @return The owner address.
    function owner() external view returns (address);
}

dependencies/rain-extrospection-0.1.14/src/lib/EVMOpcodes.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @dev EVM opcode constants current through Cancun. Each constant is the
/// canonical opcode byte value. Derived bitmaps: `HALTING_BITMAP` encodes the
/// opcodes at which the reachability scan pauses; `METAMORPHIC_OPS`
/// encodes opcodes that indicate metamorphic risk; `NON_STATIC_OPS` encodes
/// opcodes disallowed by EIP-214 static calls; `INTERPRETER_DISALLOWED_OPS`
/// encodes opcodes disallowed for Rain interpreters.

uint8 constant EVM_OP_STOP = 0x00;

uint8 constant EVM_OP_ADD = 0x01;
uint8 constant EVM_OP_MUL = 0x02;
uint8 constant EVM_OP_SUB = 0x03;
uint8 constant EVM_OP_DIV = 0x04;
uint8 constant EVM_OP_SDIV = 0x05;
uint8 constant EVM_OP_MOD = 0x06;
uint8 constant EVM_OP_SMOD = 0x07;
uint8 constant EVM_OP_ADDMOD = 0x08;
uint8 constant EVM_OP_MULMOD = 0x09;
uint8 constant EVM_OP_EXP = 0x0A;
uint8 constant EVM_OP_SIGNEXTEND = 0x0B;

uint8 constant EVM_OP_LT = 0x10;
uint8 constant EVM_OP_GT = 0x11;
uint8 constant EVM_OP_SLT = 0x12;
uint8 constant EVM_OP_SGT = 0x13;
uint8 constant EVM_OP_EQ = 0x14;
uint8 constant EVM_OP_ISZERO = 0x15;

uint8 constant EVM_OP_AND = 0x16;
uint8 constant EVM_OP_OR = 0x17;
uint8 constant EVM_OP_XOR = 0x18;
uint8 constant EVM_OP_NOT = 0x19;
uint8 constant EVM_OP_BYTE = 0x1A;
uint8 constant EVM_OP_SHL = 0x1B;
uint8 constant EVM_OP_SHR = 0x1C;
uint8 constant EVM_OP_SAR = 0x1D;

uint8 constant EVM_OP_SHA3 = 0x20;

uint8 constant EVM_OP_ADDRESS = 0x30;
uint8 constant EVM_OP_BALANCE = 0x31;

uint8 constant EVM_OP_ORIGIN = 0x32;
uint8 constant EVM_OP_CALLER = 0x33;
uint8 constant EVM_OP_CALLVALUE = 0x34;
uint8 constant EVM_OP_CALLDATALOAD = 0x35;
uint8 constant EVM_OP_CALLDATASIZE = 0x36;
uint8 constant EVM_OP_CALLDATACOPY = 0x37;

uint8 constant EVM_OP_CODESIZE = 0x38;
uint8 constant EVM_OP_CODECOPY = 0x39;

uint8 constant EVM_OP_GASPRICE = 0x3A;

uint8 constant EVM_OP_EXTCODESIZE = 0x3B;
uint8 constant EVM_OP_EXTCODECOPY = 0x3C;

uint8 constant EVM_OP_RETURNDATASIZE = 0x3D;
uint8 constant EVM_OP_RETURNDATACOPY = 0x3E;

uint8 constant EVM_OP_EXTCODEHASH = 0x3F;
uint8 constant EVM_OP_BLOCKHASH = 0x40;

uint8 constant EVM_OP_COINBASE = 0x41;
uint8 constant EVM_OP_TIMESTAMP = 0x42;
uint8 constant EVM_OP_NUMBER = 0x43;
uint8 constant EVM_OP_DIFFICULTY = 0x44;
uint8 constant EVM_OP_GASLIMIT = 0x45;
uint8 constant EVM_OP_CHAINID = 0x46;

uint8 constant EVM_OP_SELFBALANCE = 0x47;

uint8 constant EVM_OP_BASEFEE = 0x48;
uint8 constant EVM_OP_BLOBHASH = 0x49;
uint8 constant EVM_OP_BLOBBASEFEE = 0x4A;

uint8 constant EVM_OP_POP = 0x50;
uint8 constant EVM_OP_MLOAD = 0x51;
uint8 constant EVM_OP_MSTORE = 0x52;
uint8 constant EVM_OP_MSTORE8 = 0x53;

uint8 constant EVM_OP_SLOAD = 0x54;
uint8 constant EVM_OP_SSTORE = 0x55;

uint8 constant EVM_OP_JUMP = 0x56;
uint8 constant EVM_OP_JUMPI = 0x57;
uint8 constant EVM_OP_PC = 0x58;
uint8 constant EVM_OP_MSIZE = 0x59;
uint8 constant EVM_OP_GAS = 0x5A;
uint8 constant EVM_OP_JUMPDEST = 0x5B;
uint8 constant EVM_OP_TLOAD = 0x5C;
uint8 constant EVM_OP_TSTORE = 0x5D;
uint8 constant EVM_OP_MCOPY = 0x5E;

uint8 constant EVM_OP_PUSH0 = 0x5F;
uint8 constant EVM_OP_PUSH1 = 0x60;
uint8 constant EVM_OP_PUSH2 = 0x61;
uint8 constant EVM_OP_PUSH3 = 0x62;
uint8 constant EVM_OP_PUSH4 = 0x63;
uint8 constant EVM_OP_PUSH5 = 0x64;
uint8 constant EVM_OP_PUSH6 = 0x65;
uint8 constant EVM_OP_PUSH7 = 0x66;
uint8 constant EVM_OP_PUSH8 = 0x67;
uint8 constant EVM_OP_PUSH9 = 0x68;
uint8 constant EVM_OP_PUSH10 = 0x69;
uint8 constant EVM_OP_PUSH11 = 0x6A;
uint8 constant EVM_OP_PUSH12 = 0x6B;
uint8 constant EVM_OP_PUSH13 = 0x6C;
uint8 constant EVM_OP_PUSH14 = 0x6D;
uint8 constant EVM_OP_PUSH15 = 0x6E;
uint8 constant EVM_OP_PUSH16 = 0x6F;
uint8 constant EVM_OP_PUSH17 = 0x70;
uint8 constant EVM_OP_PUSH18 = 0x71;
uint8 constant EVM_OP_PUSH19 = 0x72;
uint8 constant EVM_OP_PUSH20 = 0x73;
uint8 constant EVM_OP_PUSH21 = 0x74;
uint8 constant EVM_OP_PUSH22 = 0x75;
uint8 constant EVM_OP_PUSH23 = 0x76;
uint8 constant EVM_OP_PUSH24 = 0x77;
uint8 constant EVM_OP_PUSH25 = 0x78;
uint8 constant EVM_OP_PUSH26 = 0x79;
uint8 constant EVM_OP_PUSH27 = 0x7A;
uint8 constant EVM_OP_PUSH28 = 0x7B;
uint8 constant EVM_OP_PUSH29 = 0x7C;
uint8 constant EVM_OP_PUSH30 = 0x7D;
uint8 constant EVM_OP_PUSH31 = 0x7E;
uint8 constant EVM_OP_PUSH32 = 0x7F;

uint8 constant EVM_OP_DUP1 = 0x80;
uint8 constant EVM_OP_DUP2 = 0x81;
uint8 constant EVM_OP_DUP3 = 0x82;
uint8 constant EVM_OP_DUP4 = 0x83;
uint8 constant EVM_OP_DUP5 = 0x84;
uint8 constant EVM_OP_DUP6 = 0x85;
uint8 constant EVM_OP_DUP7 = 0x86;
uint8 constant EVM_OP_DUP8 = 0x87;
uint8 constant EVM_OP_DUP9 = 0x88;
uint8 constant EVM_OP_DUP10 = 0x89;
uint8 constant EVM_OP_DUP11 = 0x8A;
uint8 constant EVM_OP_DUP12 = 0x8B;
uint8 constant EVM_OP_DUP13 = 0x8C;
uint8 constant EVM_OP_DUP14 = 0x8D;
uint8 constant EVM_OP_DUP15 = 0x8E;
uint8 constant EVM_OP_DUP16 = 0x8F;

uint8 constant EVM_OP_SWAP1 = 0x90;
uint8 constant EVM_OP_SWAP2 = 0x91;
uint8 constant EVM_OP_SWAP3 = 0x92;
uint8 constant EVM_OP_SWAP4 = 0x93;
uint8 constant EVM_OP_SWAP5 = 0x94;
uint8 constant EVM_OP_SWAP6 = 0x95;
uint8 constant EVM_OP_SWAP7 = 0x96;
uint8 constant EVM_OP_SWAP8 = 0x97;
uint8 constant EVM_OP_SWAP9 = 0x98;
uint8 constant EVM_OP_SWAP10 = 0x99;
uint8 constant EVM_OP_SWAP11 = 0x9A;
uint8 constant EVM_OP_SWAP12 = 0x9B;
uint8 constant EVM_OP_SWAP13 = 0x9C;
uint8 constant EVM_OP_SWAP14 = 0x9D;
uint8 constant EVM_OP_SWAP15 = 0x9E;
uint8 constant EVM_OP_SWAP16 = 0x9F;

uint8 constant EVM_OP_LOG0 = 0xA0;
uint8 constant EVM_OP_LOG1 = 0xA1;
uint8 constant EVM_OP_LOG2 = 0xA2;
uint8 constant EVM_OP_LOG3 = 0xA3;
uint8 constant EVM_OP_LOG4 = 0xA4;

uint8 constant EVM_OP_CREATE = 0xF0;
uint8 constant EVM_OP_CALL = 0xF1;
uint8 constant EVM_OP_CALLCODE = 0xF2;
uint8 constant EVM_OP_RETURN = 0xF3;
uint8 constant EVM_OP_DELEGATECALL = 0xF4;
uint8 constant EVM_OP_CREATE2 = 0xF5;
uint8 constant EVM_OP_STATICCALL = 0xFA;
uint8 constant EVM_OP_REVERT = 0xFD;
uint8 constant EVM_OP_INVALID = 0xFE;
uint8 constant EVM_OP_SELFDESTRUCT = 0xFF;

/// @dev Bitmap of exactly six opcodes at which
/// `LibExtrospectBytecode.scanEVMOpcodesReachableInBytecode` pauses scanning
/// until the next JUMPDEST: STOP, RETURN, REVERT, INVALID, SELFDESTRUCT, and
/// unconditional JUMP (which cannot fall through). The byte values Cancun
/// leaves unassigned (0x0C-0x0F, 0x1E-0x1F, 0x21-0x2F, 0x4B-0x4F, 0xA5-0xEF,
/// 0xF6-0xF9, 0xFB, 0xFC) are not members, so the scan does not pause at them.
//forge-lint: disable-next-line(incorrect-shift)
uint256 constant HALTING_BITMAP = (1 << EVM_OP_STOP) | (1 << EVM_OP_RETURN) | (1 << EVM_OP_REVERT)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_INVALID) | (1 << EVM_OP_SELFDESTRUCT)
    // unconditional jump always halts current flow as it cannot fall through
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_JUMP);

/// @dev Bitmap of opcodes that indicate metamorphic risk. Members: SELFDESTRUCT,
/// DELEGATECALL, CALLCODE, CREATE, CREATE2.
/// `LibExtrospectMetamorphic.scanMetamorphicRisk` masks a reachable-opcode scan
/// against this bitmap and `checkNotMetamorphic` rejects any bytecode with a
/// non-zero result. Membership is by opcode alone and is not conditioned on
/// whether the bytecode's own code can in fact be replaced, so bytecode that
/// only deploys child contracts is rejected for CREATE or CREATE2.
/// Bytecode whose first byte is the EIP-3541 reserved `0xEF` never reaches
/// this mask: `scanMetamorphicRisk` fails closed on it first and reports
/// `1 << 0xEF`, a bit that is not a member here.
//forge-lint: disable-next-line(incorrect-shift)
uint256 constant METAMORPHIC_OPS = (1 << EVM_OP_SELFDESTRUCT) | (1 << EVM_OP_DELEGATECALL)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_CALLCODE) | (1 << EVM_OP_CREATE)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_CREATE2);

/// @dev Bitmap of opcodes disallowed in a static context per EIP-214. Members:
/// CREATE, CREATE2, LOG0, LOG1, LOG2, LOG3, LOG4, SSTORE, SELFDESTRUCT,
/// CALL, TSTORE. CALL is included unconditionally (EIP-214 only disallows
/// CALL with non-zero value, but the bitmap cannot express value-conditional
/// semantics). TSTORE added per EIP-1153 (Cancun).
/// https://eips.ethereum.org/EIPS/eip-214#specification
//forge-lint: disable-next-line(incorrect-shift)
uint256 constant NON_STATIC_OPS = (1 << EVM_OP_CREATE) | (1 << EVM_OP_CREATE2)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_LOG0) | (1 << EVM_OP_LOG1) | (1 << EVM_OP_LOG2)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_LOG3)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_LOG4) | (1 << EVM_OP_SSTORE) | (1 << EVM_OP_SELFDESTRUCT)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_CALL)
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_TSTORE);

/// @dev Interpreter disallowed ops bitmap. Stricter than `NON_STATIC_OPS`,
/// adding SLOAD, TLOAD, DELEGATECALL, and CALLCODE.
uint256 constant INTERPRETER_DISALLOWED_OPS = NON_STATIC_OPS
    // Interpreter cannot store so it has no reason to load from storage.
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_SLOAD)
    // Interpreter cannot tstore so it has no reason to tload.
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_TLOAD)
    // Interpreter MUST NOT delegate call as we have no idea what could run and
    // it could easily mutate the interpreter if allowed.
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_DELEGATECALL)
    // Interpreter MUST use static call only.
    //forge-lint: disable-next-line(incorrect-shift)
    | (1 << EVM_OP_CALLCODE);

dependencies/rain-extrospection-0.1.14/src/lib/LibExtrospectBytecode.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

import {LibBytes, Pointer} from "rain-solmem-0.1.28/src/lib/LibBytes.sol";
import {EVM_OP_JUMPDEST, HALTING_BITMAP} from "./EVMOpcodes.sol";

/// @dev Byte length of the standard Solidity CBOR metadata trailer that
/// `LibExtrospectBytecode.tryTrimSolidityCBORMetadata` matches and trims. The
/// trailer is 51 bytes of CBOR body followed by 2 bytes that encode that body
/// length, so every byte of it is accounted for by
/// `SOLIDITY_CBOR_METADATA_HEAD_MASK` and `SOLIDITY_CBOR_METADATA_TAIL_MASK`
/// together.
uint256 constant SOLIDITY_CBOR_METADATA_LENGTH = 53;

/// @dev Mask for the first of the two overlapping 32-byte words that cover the
/// final `SOLIDITY_CBOR_METADATA_LENGTH` bytes of bytecode. That word holds the
/// 11 bytes preceding the metadata in memory, which are bytecode unless the
/// bytecode is shorter than 64 bytes, followed by metadata bytes 0-20. The mask
/// keeps metadata bytes 0-7 (`a2` map header, `64` text header, `69706673` as
/// `ipfs`, `5822` byte string header) and zeros both those 11 preceding bytes
/// and metadata bytes 8-20, which are the first 13 bytes of the 34-byte IPFS
/// hash.
//slither-disable-next-line too-many-digits
uint256 constant SOLIDITY_CBOR_METADATA_HEAD_MASK = 0xFFFFFFFFFFFFFFFF00000000000000000000000000;

/// @dev Mask for the second of the two overlapping 32-byte words that cover the
/// final `SOLIDITY_CBOR_METADATA_LENGTH` bytes of bytecode. That word holds
/// metadata bytes 21-52. The mask keeps metadata bytes 42-47 (`64` text header,
/// `736f6c63` as `solc`, `43` byte string header) and metadata bytes 51-52 (the
/// 2-byte body length), and zeros metadata bytes 21-41, the last 21 bytes of the
/// IPFS hash, along with metadata bytes 48-50, the 3-byte solc version.
//slither-disable-next-line too-many-digits
uint256 constant SOLIDITY_CBOR_METADATA_TAIL_MASK = 0x000000000000000000000000000000000000000000FFFFFFFFFFFF000000FFFF;

/// @dev `keccak256` of `SOLIDITY_CBOR_METADATA_HEAD_MASK` applied to the first
/// word concatenated with `SOLIDITY_CBOR_METADATA_TAIL_MASK` applied to the
/// second, for bytecode whose final `SOLIDITY_CBOR_METADATA_LENGTH` bytes are
/// standard Solidity CBOR metadata. Because the masks zero every variable byte,
/// this single hash pins every structural byte the masks keep, including the
/// `0033` body length that makes the trailer 53 bytes long.
bytes32 constant SOLIDITY_CBOR_METADATA_MASKED_HASH =
    0x0e55864b80a56accebaca64500e23598f6acfb743a5475323f0b7f2d0d268c62;

/// @title LibExtrospectBytecode
/// @notice Internal algorithms for extrospecting bytecode. Notably the EVM
/// opcode scanning needs special care, as the other bytecode functions are mere
/// wrappers around native EVM features.
library LibExtrospectBytecode {
    using LibBytes for bytes;

    /// Thrown when bytecode metadata is not trimmed as expected.
    error MetadataNotTrimmed();

    /// Thrown when `isEOFBytecode` reports the bytecode as EOF.
    error EOFBytecodeNotSupported();

    /// Thrown when the bytecode hash does not match the expected value.
    /// @param expected The expected bytecode hash.
    /// @param actual The actual bytecode hash.
    error BytecodeHashMismatch(bytes32 expected, bytes32 actual);

    /// Thrown when bytecode ends in the one Solidity CBOR metadata layout that
    /// `tryTrimSolidityCBORMetadata` matches.
    error UnexpectedMetadata();

    /// Thrown when an address-taking absence check is asked about an account
    /// that has no code. An account with no code can gain any code later — an
    /// unoccupied `CREATE2` target, a self-destructed account between
    /// incarnations, or an EOA that can gain code by EIP-7702 delegation — so
    /// absence of code proves nothing and no absence check answers "no code"
    /// as a pass.
    /// @param account The account that has no code.
    error CodelessAccount(address account);

    /// Returns whether the first two bytes of the bytecode are the EOF magic
    /// `0xEF00`. The version byte that follows the magic in an EIP-3540
    /// container is not read, so `0xEF00` alone and `0xEF00` followed by any
    /// version byte are both reported as EOF. Bytecode shorter than two bytes
    /// is not reported as EOF — explicitly including empty bytecode, such as
    /// the code of an account that has none — and neither is bytecode starting
    /// with `0xEF` followed by any byte other than `0x00`, including the
    /// `0xEF01` of an EIP-7702 delegation designator. A `false` result says
    /// the bytes are not an EOF container; over empty bytes it says nothing
    /// about what code a codeless account may later gain.
    /// @param bytecode The bytecode to check.
    /// @return isEOF Whether the first two bytes are `0xEF00`.
    function isEOFBytecode(bytes memory bytecode) internal pure returns (bool isEOF) {
        if (bytecode.length >= 2) {
            assembly ("memory-safe") {
                let firstTwoBytes := and(mload(add(bytecode, 2)), 0xFFFF)
                isEOF := eq(firstTwoBytes, 0xEF00)
            }
        }
    }

    /// Reverts with `EOFBytecodeNotSupported` if `isEOFBytecode` returns true
    /// for the bytecode.
    /// @param bytecode The bytecode to check.
    //forge-lint: disable-next-line(mixed-case-function)
    function checkNotEOFBytecode(bytes memory bytecode) internal pure {
        if (isEOFBytecode(bytecode)) {
            revert EOFBytecodeNotSupported();
        }
    }

    /// https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
    ///
    /// The encoding is not super complex, but requires having a CBOR decoder to
    /// do anything properly at all. At the time of writing, the existing CBOR
    /// decoding options in Solidity are 3+ years old and not maintained, nor is
    /// it clear what quality or maturity they have.
    ///
    /// MOST OF THE TIME, the metadata is either not present or will follow the
    /// default structure. This is:
    /// - First byte `0xa2` is cbor map header (map with 2 entries)
    /// - Next byte `0x64` is cbor text string prefix (4-byte string follows)
    /// - Next 4 bytes `0x69706673` as `ipfs` ascii/utf8
    /// - Next 2 bytes `0x5822` as cbor byte string prefix (34-byte hash follows)
    /// - Next 34 bytes are the IPFS hash (yes 34, not 32)
    /// - Next byte `0x64` is cbor text string prefix (4-byte string follows)
    /// - Next 4 bytes `0x736f6c63` as `solc` ascii/utf8
    /// - Next byte `0x43` is cbor byte string prefix (3-byte version follows)
    /// - Next 3 bytes as solc version (e.g. `0x000804`)
    /// - Final 2 bytes specify length of metadata which is always 51 bytes
    ///
    /// For the sake of trimming metadata in an 80/20 way we check that all the
    /// static parts are present and correct, and ignore the parts that change.
    /// The length of the metadata must always be 51+2 bytes, as the dynamic
    /// parts still have constant length.
    ///
    /// NOTE bytecode is mutated in place. Trimming writes the shorter length
    /// over the array's own length word, so every reference to that same array
    /// observes the trim, not just the one passed here.
    ///
    /// NOTE EOF bytecode is not supported by this function and reverts with
    /// `EOFBytecodeNotSupported`.
    ///
    /// NOTE this function constrains only the 16 structural bytes of the 53
    /// byte trailer. Taking the first trailer byte as offset 0, the constrained
    /// offsets are 0-7 (`a2 64 "ipfs" 5822`), 42-47 (`64 "solc" 43`) and 51-52
    /// (`0033`). The 34 IPFS hash bytes at offsets 8-41 and the 3 solc version
    /// bytes at offsets 48-50, 37 bytes in total, are unconstrained and may
    /// hold any value. Any 53 byte tail carrying the 16 structural bytes at
    /// those offsets is trimmed, whether or not a compiler emitted it.
    ///
    /// NOTE metadata that does not match the assumed structure is not trimmed,
    /// even if it is valid Solidity CBOR metadata or some other form of
    /// metadata, and even if it is 53 bytes long. That case DOES NOT revert or
    /// cause any other issues, it just causes the function to return `false`
    /// and leave the bytecode untrimmed.
    ///
    /// @param bytecode The bytecode to trim metadata from.
    /// @return didTrim Whether metadata was detected and trimmed.
    //forge-lint: disable-next-line(mixed-case-function)
    function tryTrimSolidityCBORMetadata(bytes memory bytecode) internal pure returns (bool didTrim) {
        checkNotEOFBytecode(bytecode);
        uint256 length = bytecode.length;
        if (length >= SOLIDITY_CBOR_METADATA_LENGTH) {
            // Two adjacent 32-byte reads span the last
            // `SOLIDITY_CBOR_METADATA_LENGTH` bytes of bytecode (the metadata)
            // plus the 11 bytes of memory immediately before them. The masks
            // zero those 11 bytes and the variable parts of the metadata
            // (34-byte IPFS hash and 3-byte solc version), preserving only the
            // fixed CBOR structure bytes: a2 64 "ipfs" 5822 ... 64 "solc" 43
            // ... 0033. The masked result hashes to
            // `SOLIDITY_CBOR_METADATA_MASKED_HASH` exactly when the metadata
            // matches.
            //slither-disable-next-line too-many-digits
            uint256 maskA = SOLIDITY_CBOR_METADATA_HEAD_MASK;
            //slither-disable-next-line too-many-digits
            uint256 maskB = SOLIDITY_CBOR_METADATA_TAIL_MASK;
            bytes32 expectedHash = SOLIDITY_CBOR_METADATA_MASKED_HASH;
            bytes32 relevantHash;
            assembly ("memory-safe") {
                // Point 0x20 bytes before the end of the bytecode.
                let end := add(bytecode, length)
                mstore(0, and(maskA, mload(sub(end, 0x20))))
                mstore(0x20, and(maskB, mload(end)))
                relevantHash := keccak256(0, 0x40)
                didTrim := eq(relevantHash, expectedHash)
                if didTrim { mstore(bytecode, sub(length, SOLIDITY_CBOR_METADATA_LENGTH)) }
            }
        }
    }

    /// Checks that the bytecode of an account, after trimming Solidity CBOR
    /// metadata, matches an expected hash. Reverts with `MetadataNotTrimmed` if
    /// the metadata was not trimmed, or with `BytecodeHashMismatch` if the hash
    /// does not match after trimming.
    ///
    /// NOTE EOF bytecode is not supported by this function and reverts with
    /// `EOFBytecodeNotSupported` before either of the above is reached.
    ///
    /// NOTE `expectedTrimmedHash` covers only the bytecode left after
    /// trimming. The 53 trimmed bytes are runtime code that the EVM executes
    /// if a jump lands in them, and 37 of them are unconstrained by
    /// `tryTrimSolidityCBORMetadata`. Two accounts whose code differs only in
    /// those 37 bytes both satisfy the same `expectedTrimmedHash`.
    ///
    /// NOTE an account whose code is exactly the 53 byte metadata trailer and
    /// nothing else trims to an empty remainder, so the trimmed hash is
    /// `keccak256("")` for every such account. As the trailer's 34 byte IPFS
    /// hash and 3 byte solc version are not constrained by the trim, an
    /// `expectedTrimmedHash` of `keccak256("")` matches all of them and does
    /// not identify any one of them.
    /// @param account The account whose bytecode to check.
    /// @param expectedTrimmedHash The expected hash of the trimmed bytecode.
    /// Not the same value as
    /// `LibExtrospectERC1967BeaconProxy.isBeaconImplementationBytecode`'s
    /// `expectedRuntimeHash`, which hashes runtime bytecode whole.
    function checkCBORTrimmedBytecodeHash(address account, bytes32 expectedTrimmedHash) internal view {
        bytes memory bytecode = account.code;
        bool didTrim = tryTrimSolidityCBORMetadata(bytecode);
        if (!didTrim) {
            revert MetadataNotTrimmed();
        }
        bytes32 actual = keccak256(bytecode);
        if (expectedTrimmedHash != actual) {
            revert BytecodeHashMismatch(expectedTrimmedHash, actual);
        }
    }

    /// Checks that no standard Solidity CBOR metadata is present in the
    /// bytecode of an account. Reverts with `UnexpectedMetadata` if metadata is
    /// detected. This is the inverse of `checkCBORTrimmedBytecodeHash` — use
    /// this when bytecode should have been compiled without metadata (e.g.
    /// `cbor_metadata = false` in foundry.toml) as a defense against the
    /// metamorphic metadata attack.
    ///
    /// NOTE EOF bytecode is not supported by this function. An account whose
    /// bytecode is EOF reverts with `EOFBytecodeNotSupported`, so for such an
    /// account neither the passing case nor `UnexpectedMetadata` is reached.
    ///
    /// NOTE detection is `tryTrimSolidityCBORMetadata`, which constrains only
    /// 16 of the 53 trailer bytes, so an account whose code merely ends with
    /// those 16 bytes at the expected offsets reverts here even if no compiler
    /// emitted metadata for it.
    ///
    /// NOTE every trailer `tryTrimSolidityCBORMetadata` does not match returns
    /// without reverting, and that includes Solidity CBOR metadata in other
    /// encodings: the solc-version-only trailer emitted when `bytecode_hash` is
    /// `none` and `cbor_metadata` is left on, `bzzr1`/Swarm hashes, reordered
    /// or additional CBOR map keys, and solc versions not encoded as `0x43`
    /// plus three bytes. Returning without reverting therefore establishes that
    /// this one layout is absent, not that the account carries no metadata.
    ///
    /// NOTE an account with no code reverts with `CodelessAccount` carrying
    /// the address, before metadata detection is attempted. Absence of code
    /// is not absence of metadata risk: a codeless account can gain any code
    /// later, so this check refuses to vouch for it.
    ///
    /// @param account The account whose bytecode to check.
    //forge-lint: disable-next-line(mixed-case-function)
    function checkNoSolidityCBORMetadata(address account) internal view {
        bytes memory bytecode = account.code;
        if (bytecode.length == 0) {
            revert CodelessAccount(account);
        }
        bool didTrim = tryTrimSolidityCBORMetadata(bytecode);
        if (didTrim) {
            revert UnexpectedMetadata();
        }
    }

    /// Scans for opcodes that are reachable during execution of a contract.
    /// Uses a linear over-approximation: scans sequentially, skipping PUSH*
    /// inline data. When a halting opcode is encountered (STOP, RETURN, REVERT,
    /// INVALID, SELFDESTRUCT, or unconditional JUMP per `HALTING_BITMAP`),
    /// scanning pauses. Scanning resumes at the next JUMPDEST. Opcodes between
    /// a halt and the next JUMPDEST are treated as unreachable and excluded.
    /// The sweep does not distinguish code from data, so a JUMPDEST byte that it
    /// lands on inside a data region such as Solidity CBOR metadata resumes
    /// scanning, and the opcodes after it in that region are reported as
    /// reachable.
    /// This is an over-approximation: not all JUMPDESTs are actually reachable
    /// at runtime, and the byte values Cancun leaves unassigned other than
    /// INVALID do not pause scanning even though the EVM halts on them.
    /// A trailing PUSH* whose inline data runs past the end of the bytecode
    /// ends the scan. The PUSH* opcode itself is recorded per the rules above,
    /// and every byte after it is treated as that PUSH*'s inline data, so none
    /// of those bytes are scanned as opcodes.
    /// Adapted from https://github.com/MrLuit/selfdestruct-detect/blob/master/src/index.ts
    /// NOTE: Reverts with `EOFBytecodeNotSupported` if the bytecode is EOF
    /// (EIP-7692).
    /// NOTE: Empty bytecode scans to a zero bitmap: there are no bytes, so no
    /// opcode is reachable. The empty code of a codeless account scans the
    /// same way, and zero says nothing about what opcodes that account may
    /// later gain. Use `scanEVMOpcodesReachableInBytecode(address)` to bind
    /// the scan to an account and reject a codeless one.
    /// @param bytecode The bytecode to scan.
    /// @return bytesReachable A `uint256` where each bit represents the presence
    /// of a reachable opcode in the source bytecode.
    //forge-lint: disable-next-line(mixed-case-function)
    function scanEVMOpcodesReachableInBytecode(bytes memory bytecode) internal pure returns (uint256 bytesReachable) {
        checkNotEOFBytecode(bytecode);
        Pointer cursor = bytecode.dataPointer();
        uint256 length = bytecode.length;
        uint256 opJumpDest = EVM_OP_JUMPDEST;
        uint256 haltingMask = HALTING_BITMAP;
        assembly ("memory-safe") {
            cursor := sub(cursor, 0x20)
            let end := add(cursor, length)
            let halted := 0
            for {} lt(cursor, end) {} {
                cursor := add(cursor, 1)
                let op := and(mload(cursor), 0xFF)
                // The 32 `PUSH*` opcodes starting at 0x60 indicate that the
                // following bytes MUST be skipped as they are inline stack
                // data and NOT opcodes.
                let push := sub(op, 0x60)
                if lt(push, 0x20) {
                    cursor := add(cursor, add(push, 1))
                }
                switch halted
                case 0 {
                    //slither-disable-next-line incorrect-shift
                    bytesReachable := or(bytesReachable, shl(op, 1))

                    //slither-disable-next-line incorrect-shift
                    if and(shl(op, 1), haltingMask) {
                        halted := 1
                    }
                    continue
                }
                case 1 {
                    if eq(op, opJumpDest) {
                        halted := 0
                        //slither-disable-next-line incorrect-shift
                        bytesReachable := or(bytesReachable, shl(op, 1))
                    }
                    continue
                }
                // Can't happen, but the compiler doesn't know that.
                default { revert(0, 0) }
            }
        }
    }

    /// Reads `account`'s code and scans it for reachable opcodes, delegating
    /// to `scanEVMOpcodesReachableInBytecode(bytes)`. Reverts with
    /// `CodelessAccount` carrying the address when the account has no code:
    /// an account with no code can gain any code later — an unoccupied
    /// `CREATE2` target, a self-destructed account between incarnations, or
    /// an EOA that can gain code by EIP-7702 delegation — so a zero bitmap
    /// for it would vouch for nothing. Reverts with `EOFBytecodeNotSupported`
    /// if the account's code is EOF, as the bytes scan does.
    /// @param account The account whose code to scan.
    /// @return A `uint256` where each bit represents the presence of a
    /// reachable opcode in the account's code.
    //forge-lint: disable-next-line(mixed-case-function)
    function scanEVMOpcodesReachableInBytecode(address account) internal view returns (uint256) {
        bytes memory bytecode = account.code;
        if (bytecode.length == 0) {
            revert CodelessAccount(account);
        }
        return scanEVMOpcodesReachableInBytecode(bytecode);
    }

    /// Scans all opcodes present in bytecode, respecting PUSH* inline data.
    /// A trailing PUSH* whose inline data runs past the end of the bytecode
    /// ends the scan. The PUSH* opcode itself is recorded, and every byte after
    /// it is treated as that PUSH*'s inline data, so none of those bytes are
    /// scanned as opcodes.
    /// Adapted from
    /// https://github.com/a16z/metamorphic-contract-detector/blob/main/metamorphic_detect/opcodes.py#L52
    /// NOTE: Reverts with `EOFBytecodeNotSupported` if the bytecode is EOF
    /// (EIP-7692).
    /// NOTE: Empty bytecode scans to a zero bitmap: there are no bytes, so no
    /// opcode is present. The empty code of a codeless account scans the same
    /// way, and zero says nothing about what opcodes that account may later
    /// gain. Use `scanEVMOpcodesPresentInBytecode(address)` to bind the scan
    /// to an account and reject a codeless one.
    /// @param bytecode The bytecode to scan.
    /// @return bytesPresent A `uint256` where each bit represents the presence
    /// of an opcode in the source bytecode.
    //forge-lint: disable-next-line(mixed-case-function)
    function scanEVMOpcodesPresentInBytecode(bytes memory bytecode) internal pure returns (uint256 bytesPresent) {
        checkNotEOFBytecode(bytecode);
        Pointer cursor = bytecode.dataPointer();
        uint256 length = bytecode.length;
        assembly ("memory-safe") {
            cursor := sub(cursor, 0x20)
            let end := add(cursor, length)
            for {} lt(cursor, end) {} {
                cursor := add(cursor, 1)

                let op := and(mload(cursor), 0xFF)
                //slither-disable-next-line incorrect-shift
                bytesPresent := or(bytesPresent, shl(op, 1))

                // The 32 `PUSH*` opcodes starting at 0x60 indicate that the
                // following bytes MUST be skipped as they are inline stack data
                // and NOT opcodes.
                let push := sub(op, 0x60)
                if lt(push, 0x20) { cursor := add(cursor, add(push, 1)) }
            }
        }
    }

    /// Reads `account`'s code and scans it for present opcodes, delegating to
    /// `scanEVMOpcodesPresentInBytecode(bytes)`. Reverts with
    /// `CodelessAccount` carrying the address when the account has no code:
    /// an account with no code can gain any code later — an unoccupied
    /// `CREATE2` target, a self-destructed account between incarnations, or
    /// an EOA that can gain code by EIP-7702 delegation — so a zero bitmap
    /// for it would vouch for nothing. Reverts with `EOFBytecodeNotSupported`
    /// if the account's code is EOF, as the bytes scan does.
    /// @param account The account whose code to scan.
    /// @return A `uint256` where each bit represents the presence of an
    /// opcode in the account's code.
    //forge-lint: disable-next-line(mixed-case-function)
    function scanEVMOpcodesPresentInBytecode(address account) internal view returns (uint256) {
        bytes memory bytecode = account.code;
        if (bytecode.length == 0) {
            revert CodelessAccount(account);
        }
        return scanEVMOpcodesPresentInBytecode(bytecode);
    }
}

dependencies/rain-extrospection-0.1.14/src/lib/LibExtrospectERC1167Proxy.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @dev The 10 bytes before the implementation address in an ERC1167 proxy.
bytes constant ERC1167_PREFIX = hex"363d3d373d3d3d363d73";
/// @dev The 15 bytes after the implementation address in an ERC1167 proxy.
bytes constant ERC1167_SUFFIX = hex"5af43d82803e903d91602b57fd5bf3";
/// @dev The length in bytes of `ERC1167_PREFIX`.
uint256 constant ERC1167_PREFIX_LENGTH = 10;
/// @dev The length in bytes of `ERC1167_SUFFIX`.
uint256 constant ERC1167_SUFFIX_LENGTH = 15;
/// @dev The length in bytes of the implementation address in an ERC1167 proxy.
/// An address is 20 bytes.
uint256 constant ERC1167_IMPLEMENTATION_ADDRESS_LENGTH = 20;
/// @dev The length of a proxy contract is the prefix, then the implementation
/// address, then the suffix, each of which is a constant length.
uint256 constant ERC1167_PROXY_LENGTH =
    ERC1167_PREFIX_LENGTH + ERC1167_IMPLEMENTATION_ADDRESS_LENGTH + ERC1167_SUFFIX_LENGTH;
/// @dev We can more efficiently compare equality of hashes of regions of memory
/// than the regions themselves.
/// This is `keccak256(ERC1167_PREFIX)`, spelled as a literal so that using it
/// allocates no memory.
bytes32 constant ERC1167_PREFIX_HASH = 0x63d391efc3119310b9796819854d0555ea77fb380e9ef5190c2359a8094c1f3c;
/// @dev We can more efficiently compare equality of hashes of regions of memory
/// than the regions themselves.
/// This is `keccak256(ERC1167_SUFFIX)`, spelled as a literal so that using it
/// allocates no memory.
bytes32 constant ERC1167_SUFFIX_HASH = 0x11a195f66c9175f46895bae2006d40848a680c7068b9fc4af248ff9a54a47e45;
/// @dev The bounds of the ERC1167 proxy prefix are constant.
/// This is the start offset of the ERC1167 proxy prefix, measured from the
/// pointer to the bytecode. The first `0x20` bytes at the pointer are the
/// length of the bytecode, so the bytecode itself starts `0x20` after it.
uint256 constant ERC1167_PREFIX_START = 0x20;
/// @dev The bounds of the ERC1167 proxy suffix are constant.
/// This is the start offset of the ERC1167 proxy suffix.
uint256 constant ERC1167_SUFFIX_START = ERC1167_PREFIX_START + ERC1167_PROXY_LENGTH - ERC1167_SUFFIX_LENGTH;
/// @dev The implementation address read offset is constant. The address is read
/// with a single `mload`, which reads the `0x20` bytes at and above its
/// argument, so the argument is `0x20` below the end of the address. The end of
/// the address is the start of the prefix, plus the prefix, plus the address.
uint256 constant ERC1167_IMPLEMENTATION_ADDRESS_OFFSET =
    ERC1167_PREFIX_START + ERC1167_PREFIX_LENGTH + ERC1167_IMPLEMENTATION_ADDRESS_LENGTH - 0x20;

/// @title LibExtrospectERC1167Proxy
/// @notice Detection of ERC-1167 minimal proxy contracts and extraction of
/// their implementation address from bytecode.
/// https://eips.ethereum.org/EIPS/eip-1167
library LibExtrospectERC1167Proxy {
    /// @notice Checks if the given bytecode is the canonical ERC1167 minimal
    /// proxy. If so, returns the implementation address.
    ///
    /// Exactly one byte sequence matches: the 10 byte prefix, then a 20 byte
    /// implementation address pushed by `PUSH20`, then the 15 byte suffix
    /// whose jump target is `0x2b`. Every other bytecode does not match,
    /// including bytecode that delegates all of its calls to another account:
    /// - ERC1167 vanity proxies, which push the implementation address with
    ///   `PUSH(20 - Z)` and jump to `0x2b - Z` for a total length of `45 - Z`
    ///   when the address has `Z` leading zero bytes;
    /// - minimal proxies that push their zero constants with `PUSH0` instead of
    ///   `RETURNDATASIZE`;
    /// - EIP-7702 delegation designators, which are `0xef0100` followed by the
    ///   20 byte address that the account delegates to.
    ///
    /// A `false` result says that the bytecode is not the canonical minimal
    /// proxy. It does not say that the account runs its own code.
    ///
    /// Empty bytecode is not 45 bytes long, so it returns
    /// `(false, address(0))` like every other length mismatch — explicitly
    /// including the empty code of a codeless account, for which `false`
    /// says only that no proxy code is present now, not that the account can
    /// never gain any.
    ///
    /// The verdict is a function of the 45 bytes alone. It is the same whether
    /// or not the implementation account exists or has code.
    ///
    /// EOF bytecode does not revert. An EOF container begins with `0xEF00`,
    /// which is not `ERC1167_PREFIX`, so EOF bytecode returns
    /// `(false, address(0))`.
    /// @param bytecode The bytecode to check.
    /// @return result True if the bytecode is the canonical ERC1167 minimal
    /// proxy.
    /// @return implementationAddress The address of the implementation contract.
    /// This is only valid if `result` is true, else it is zero. When `result`
    /// is true this is whatever address the bytecode encodes, which includes
    /// `address(0)`, so `result` is the only discriminator between a proxy and
    /// a non-proxy.
    function isERC1167Proxy(bytes memory bytecode) internal pure returns (bool result, address implementationAddress) {
        unchecked {
            {
                // The bytecode must be the correct length. As the majority of
                // accounts onchain are EOAs or contracts that are not ERC1167
                // proxies, this is a cheap check to perform first and return
                // early if it fails.
                if (bytecode.length != ERC1167_PROXY_LENGTH) {
                    return (false, address(0));
                } else {
                    // Assume the bytecode is an ERC1167 proxy. If any of the
                    // checks fail, this will be set to false.
                    result = true;
                }
            }

            // The bytecode must start with the prefix.
            uint256 prefixStart = ERC1167_PREFIX_START;
            uint256 prefixLength = ERC1167_PREFIX_LENGTH;
            bytes32 prefixHash = ERC1167_PREFIX_HASH;
            assembly ("memory-safe") {
                result := and(result, eq(keccak256(add(bytecode, prefixStart), prefixLength), prefixHash))
            }

            {
                // The bytecode must end with the suffix.
                uint256 suffixStart = ERC1167_SUFFIX_START;
                uint256 suffixLength = ERC1167_SUFFIX_LENGTH;
                bytes32 suffixHash = ERC1167_SUFFIX_HASH;
                assembly ("memory-safe") {
                    result := and(result, eq(keccak256(add(bytecode, suffixStart), suffixLength), suffixHash))
                }
            }

            {
                if (result) {
                    // If the bytecode is an ERC1167 proxy, extract the
                    // implementation address.
                    uint256 implementationAddressOffset = ERC1167_IMPLEMENTATION_ADDRESS_OFFSET;
                    uint256 implementationAddressMask = type(uint160).max;
                    assembly ("memory-safe") {
                        implementationAddress := and(
                            mload(add(bytecode, implementationAddressOffset)),
                            implementationAddressMask
                        )
                    }
                }
            }
        }
    }
}

dependencies/rain-extrospection-0.1.14/src/lib/LibExtrospectERC1967BeaconProxy.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

import {IBeacon} from "../interface/IBeacon.sol";
import {IOwnable} from "../interface/IOwnable.sol";

/// @dev EIP-1967 implementation storage slot, derived in-source from the
/// spec formula. Evaluated at compile time, zero runtime cost.
bytes32 constant ERC1967_IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);

/// @dev EIP-1967 admin storage slot, derived in-source from the spec
/// formula.
bytes32 constant ERC1967_ADMIN_SLOT = bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);

/// @dev EIP-1967 beacon storage slot, derived in-source from the spec
/// formula.
bytes32 constant ERC1967_BEACON_SLOT = bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1);

/// @title LibExtrospectERC1967BeaconProxy
/// @notice Extrospection of ERC-1967 beacon proxies and the beacons
/// they point at.
///
/// What's possible from a runtime contract context (no cheat codes):
///
/// - Read a beacon's implementation via `IBeacon.implementation()` —
///   well-defined interface, callable from anywhere.
/// - Read a beacon's owner via `Ownable.owner()` — de-facto convention
///   for beacons that inherit OZ `Ownable` or equivalent.
/// - Hash a contract's runtime bytecode via `keccak256(addr.code)` to
///   compare against an expected template.
///
/// What's NOT possible from a runtime contract context:
///
/// - Reading a proxy's beacon storage slot directly. ERC-1967 specifies
///   the slot but not a getter — proxies route everything through
///   `delegatecall`, with no public function exposing the slot. To read
///   it you need either Foundry's `vm.load` (tests), an off-chain
///   `eth_getStorageAt`, or `sload` from a delegatecall context running
///   as the proxy.
///
/// The slot is not the only place a proxy holds its beacon. OpenZeppelin
/// v5 `BeaconProxy` also holds it in `address private immutable _beacon`,
/// which solc inlines into the proxy's runtime bytecode, so `proxy.code`
/// carries the 20 address bytes and any contract can read them.
/// OpenZeppelin v4 `BeaconProxy` has no such immutable, so its runtime
/// bytecode does not carry the address. This library extracts a beacon
/// address from neither.
///
/// EIP-7702 delegated accounts:
///
/// - An account whose code is a 23-byte delegation designator
///   (`0xef0100` followed by a 20-byte delegate address) runs the
///   delegate's code on every call, so it answers `implementation()`
///   and `owner()` and both predicates below can return true for it.
///   Neither predicate inspects the target's code, so a delegated
///   account is indistinguishable from a beacon contract in what they
///   return.
/// - The account holder repoints or revokes the designator in a single
///   transaction, so a true from either predicate about such an account
///   changes without any contract's code changing.
/// - `keccak256(addr.code)` on a delegated account hashes the 23-byte
///   designator, not the delegate's runtime bytecode.
///
/// The slot constants are exported so callers that have storage access
/// elsewhere use a single canonical source for the slot addresses.
library LibExtrospectERC1967BeaconProxy {
    /// @notice Read a beacon's current implementation address via
    /// `IBeacon.implementation()`. Yields `(false, address(0))` rather
    /// than reverting for a target that doesn't expose
    /// `implementation()`, whose call reverts, or whose return data is
    /// not exactly 32 bytes holding a clean address. Callers that need
    /// the implementation's bytecode properties feed the returned
    /// address to `LibExtrospectMetamorphic` / `LibExtrospectBytecode`.
    /// @param beacon The beacon address to query.
    /// @return True if the call to `implementation()` returned a clean
    /// address. False if it failed for any reason.
    /// @return The implementation address the beacon reports.
    /// `address(0)` whenever the first return value is false.
    function beaconImplementation(address beacon) internal view returns (bool, address) {
        return _tryGetAddress(beacon, IBeacon.implementation.selector);
    }

    /// @notice Verify that a beacon's current implementation has runtime
    /// bytecode matching `expectedRuntimeHash`. Useful for asserting a
    /// known-good implementation is behind the beacon. A target whose
    /// `implementation()` call reverts, or answers with anything other
    /// than 32 bytes that decode as an address, fails the check —
    /// returns false rather than reverting, so integrators can collapse
    /// the predicate into a single boolean assertion.
    ///
    /// The caller is responsible for only calling this on beacons.
    ///
    /// An implementation address with no code — an externally owned
    /// account, an unoccupied `CREATE2` target, a self-destructed
    /// account, or `address(0)` — reads as empty bytecode and hashes to
    /// `keccak256("")`, so `expectedRuntimeHash == keccak256("")` is
    /// satisfied by every codeless implementation. Whether the
    /// implementation has any code at all is not checked. Deploying code
    /// to a codeless implementation turns that same call from true to
    /// false.
    ///
    /// An EIP-7702 delegated account answers `implementation()` from its
    /// delegate and so satisfies this check; when `implementation()`
    /// itself returns a delegated account, the hash compared is that of
    /// its 23-byte delegation designator rather than of the delegate's
    /// runtime bytecode.
    /// @param beacon The beacon address to query.
    /// @param expectedRuntimeHash The expected `keccak256` of the
    /// implementation's whole runtime bytecode, including any Solidity CBOR
    /// metadata trailer. Not the same value as
    /// `LibExtrospectBytecode.checkCBORTrimmedBytecodeHash`'s
    /// `expectedTrimmedHash`, which hashes runtime bytecode with that trailer
    /// removed.
    /// @return True if the beacon's current implementation has matching
    /// runtime bytecode. False if the call to `implementation()` fails
    /// for any reason.
    function isBeaconImplementationBytecode(address beacon, bytes32 expectedRuntimeHash) internal view returns (bool) {
        (bool ok, address impl) = _tryGetAddress(beacon, IBeacon.implementation.selector);
        return ok && keccak256(impl.code) == expectedRuntimeHash;
    }

    /// @notice Verify that `beacon`'s current owner equals
    /// `expectedOwner`. A target whose `owner()` call reverts, or
    /// answers with anything other than 32 bytes that decode as an
    /// address, fails the check — returns false rather than reverting,
    /// so integrators can collapse the predicate into a single boolean
    /// assertion.
    ///
    /// The caller is responsible for only calling this on beacons.
    ///
    /// An EIP-7702 delegated account answers `owner()` from its
    /// delegate and so satisfies this check.
    /// @param beacon The beacon address to query.
    /// @param expectedOwner The owner address the beacon should report.
    /// @return True if the ownership matches. False if the call to
    /// `owner()` fails for any reason.
    function isBeaconOwner(address beacon, address expectedOwner) internal view returns (bool) {
        (bool ok, address own) = _tryGetAddress(beacon, IOwnable.owner.selector);
        return ok && own == expectedOwner;
    }

    /// @dev Static-call `selector` on `target` and decode the return as
    /// `address`. Returns `(false, _)` on three failure modes:
    /// low-level call revert, return data that isn't exactly 32 bytes,
    /// or 32-byte return data whose upper 12 bytes are non-zero (which
    /// `abi.decode(_, (address))` would reject as a dirty address).
    ///
    /// A missing selector is only ever rejected through one of those
    /// three, via whatever `target`'s fallback does: no fallback or a
    /// reverting one is the revert case, and a fallback answering with
    /// something other than 32 clean bytes is one of the other two. A
    /// fallback answering with 32 clean bytes is accepted, so
    /// `(true, addr)` says that `target` answered `selector` with
    /// `addr` and nothing more.
    ///
    /// High-level `try IBeacon(...).implementation()` catches the
    /// first two but lets the dirty-address Panic escape, so we go
    /// through the low-level call to fold all three into a single
    /// boolean.
    ///
    /// The call forwards all remaining gas.
    ///
    /// The call discards its return data. The size is read from
    /// `returndatasize()` and at most 32 bytes are ever copied into
    /// memory, so the caller's memory cost is the same constant for
    /// every target, whatever the target returns.
    function _tryGetAddress(address target, bytes4 selector) private view returns (bool, address) {
        // Low-level staticcall is required to validate return-data length
        // and reject dirty address bits ourselves; high-level
        // `try IBeacon(...).implementation() returns (address)` lets the
        // dirty-address Panic escape past the catch.
        uint256 ok;
        uint256 raw;
        assembly ("memory-safe") {
            // Scratch space at 0x00 holds the 4 byte calldata, then the
            // 32 bytes of return data. `selector` is left aligned in its
            // word, so the 4 selector bytes land at 0x00.
            mstore(0, selector)
            ok := staticcall(gas(), target, 0, 4, 0, 0)
            ok := and(ok, eq(returndatasize(), 0x20))
            if ok {
                returndatacopy(0, 0, 0x20)
                raw := mload(0)
            }
        }
        if (ok == 0 || raw > type(uint160).max) return (false, address(0));
        return (true, address(uint160(raw)));
    }
}

dependencies/rain-extrospection-0.1.14/src/lib/LibExtrospectMetamorphic.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

import {LibExtrospectBytecode} from "./LibExtrospectBytecode.sol";
import {METAMORPHIC_OPS} from "./EVMOpcodes.sol";

/// @dev The lead byte EIP-3541 reserves: since the London hard fork no
/// ordinary deployment can produce code whose first byte is `0xEF`. On a
/// post-London chain new code beginning with it comes from protocol
/// features — an EOF container (`0xEF00`), an EIP-7702 delegation
/// designator (`0xEF0100 || address`), or whatever the prefix is assigned
/// next — none of which a legacy opcode scan can reason about; pre-London
/// deployments and chains without EIP-3541 can carry it as plain legacy
/// code the scan cannot tell apart by inspection. The metamorphic scan
/// fails closed on the first byte alone.
uint8 constant EIP3541_RESERVED_LEAD_BYTE = 0xEF;

/// @title LibExtrospectMetamorphic
/// @notice Detection and guarding against metamorphic contract risk. Scans
/// bytecode for reachable opcodes in `METAMORPHIC_OPS`, failing closed on
/// bytecode whose first byte is the EIP-3541 reserved `0xEF`: such code is a
/// protocol-defined format, not legacy opcodes, and the scan reports the
/// `0xEF` byte itself as the risky element rather than vouch for bytes it
/// cannot disassemble. The bytes-taking entry points are total over bytes and
/// answer only about the bytes given; the address-taking entry points bind
/// the verdict to an account and revert with `CodelessAccount` rather than
/// vouch for an account that has no code.
library LibExtrospectMetamorphic {
    /// Thrown when metamorphic risk opcodes are reachable in bytecode.
    /// @param riskyOpcodes Bitmap of reachable metamorphic opcodes.
    error Metamorphic(uint256 riskyOpcodes);

    /// Scans bytecode for reachable metamorphic risk opcodes. Total over
    /// bytes: never reverts, and answers only about the bytes given. Use
    /// `scanMetamorphicRisk(address)` to bind the scan to an account and
    /// reject a codeless one.
    ///
    /// Bytecode whose first byte is the EIP-3541 reserved `0xEF` fails
    /// closed: the scan reports a bitmap of exactly `1 << 0xEF` before any
    /// opcode scan, whatever the remaining bytes are. EIP-3541 reserves the
    /// prefix for protocol features — an EOF container (`0xEF00`), an
    /// EIP-7702 delegation designator (`0xEF0100 || address`, which the
    /// account holder repoints or revokes with one transaction), or
    /// whatever it is assigned next — that a legacy opcode scan cannot
    /// reason about; pre-London deployments and chains without EIP-3541
    /// can hold `0xEF`-lead legacy code indistinguishable by inspection.
    /// The verdict keys on the first byte alone and vouches for none of
    /// it. The reported bit
    /// is the `0xEF` lead byte itself, not a reachable opcode, and is not a
    /// member of `METAMORPHIC_OPS`. The reserved prefix is the one first
    /// byte that never reaches `scanEVMOpcodesReachableInBytecode`, so
    /// `EOFBytecodeNotSupported` is never thrown here.
    /// @param bytecode The bytecode to scan.
    /// @return Bitmap of risky elements: the reachable metamorphic opcodes,
    /// or exactly `1 << 0xEF` when the first byte is the reserved `0xEF`.
    /// Zero if no metamorphic risk opcodes are reachable, including when
    /// `bytecode` is empty.
    function scanMetamorphicRisk(bytes memory bytecode) internal pure returns (uint256) {
        if (bytecode.length > 0 && uint8(bytecode[0]) == EIP3541_RESERVED_LEAD_BYTE) {
            //forge-lint: disable-next-line(incorrect-shift)
            return uint256(1) << EIP3541_RESERVED_LEAD_BYTE;
        }
        return LibExtrospectBytecode.scanEVMOpcodesReachableInBytecode(bytecode) & METAMORPHIC_OPS;
    }

    /// Reverts with `Metamorphic` when `scanMetamorphicRisk` reports a
    /// nonzero bitmap for the bytecode: any reachable metamorphic risk
    /// opcode, or a first byte of the EIP-3541 reserved `0xEF` — an EOF
    /// container, an EIP-7702 delegation designator, or any future
    /// assignment of the prefix — which reverts `Metamorphic(1 << 0xEF)`.
    /// Never reverts `EOFBytecodeNotSupported`.
    /// Empty bytecode has no reachable metamorphic opcodes and does not revert,
    /// so an account with no code — an externally owned account, an unoccupied
    /// `CREATE2` target, or a self-destructed account — passes this check on
    /// the same terms as an account whose code has no reachable metamorphic
    /// opcodes. Whether the account has any code at all is not checked here.
    /// Use `checkNotMetamorphic(address)` to bind the verdict to an account
    /// and reject a codeless one.
    /// @param bytecode The bytecode to check.
    function checkNotMetamorphic(bytes memory bytecode) internal pure {
        uint256 riskyOpcodes = scanMetamorphicRisk(bytecode);
        if (riskyOpcodes != 0) {
            revert Metamorphic(riskyOpcodes);
        }
    }

    /// Reads `account`'s code and scans it for reachable metamorphic risk
    /// opcodes, delegating to `scanMetamorphicRisk(bytes)`. Reverts with
    /// `CodelessAccount` carrying the address when the account has no code:
    /// an account with no code is the maximally metamorphic state — an
    /// unoccupied `CREATE2` target, a self-destructed account between
    /// incarnations, or an EOA that can gain code by EIP-7702 delegation —
    /// and the chain cannot distinguish "can never gain code" from "can gain
    /// anything", so a zero bitmap for it would vouch for nothing. Account
    /// code whose first byte is the EIP-3541 reserved `0xEF` — an EOF
    /// container or an EIP-7702 delegation designator — reports exactly
    /// `1 << 0xEF`, as the bytes scan does.
    /// @param account The account whose code to scan.
    /// @return Bitmap of risky elements in the account's code: the reachable
    /// metamorphic opcodes, or exactly `1 << 0xEF` when the code's first
    /// byte is the reserved `0xEF`. Zero if none are reachable.
    function scanMetamorphicRisk(address account) internal view returns (uint256) {
        bytes memory bytecode = account.code;
        if (bytecode.length == 0) {
            revert LibExtrospectBytecode.CodelessAccount(account);
        }
        return scanMetamorphicRisk(bytecode);
    }

    /// Reads `account`'s code and reverts with `Metamorphic` if any
    /// metamorphic risk opcodes are reachable in it, delegating to
    /// `scanMetamorphicRisk(address)`. Reverts with `CodelessAccount`
    /// carrying the address when the account has no code, on the same terms
    /// as `scanMetamorphicRisk(address)`: no absence check answers "no code"
    /// as a pass. Reverts with `Metamorphic(1 << 0xEF)` when the account's
    /// code begins with the EIP-3541 reserved `0xEF` — an EOF container or
    /// an EIP-7702 delegation designator — as the bytes check does.
    /// @param account The account whose code to check.
    function checkNotMetamorphic(address account) internal view {
        uint256 riskyOpcodes = scanMetamorphicRisk(account);
        if (riskyOpcodes != 0) {
            revert Metamorphic(riskyOpcodes);
        }
    }
}

dependencies/rain-solmem-0.1.28/src/error/ErrTruncate.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// Thrown if a truncated length is longer than the data being truncated. It is
/// not possible to truncate something and increase its length as the memory
/// region after it MAY be allocated for something else already. Thrown by
/// `LibBytes`, `LibUint256Array` and `LibBytes32Array` alike.
/// @param currentLength The current length of the data.
/// @param truncatedLength The requested, longer, length.
error OutOfBoundsTruncate(uint256 currentLength, uint256 truncatedLength);

dependencies/rain-solmem-0.1.28/src/lib/LibBytes.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

import {Pointer} from "./LibPointer.sol";
import {OutOfBoundsTruncate} from "../error/ErrTruncate.sol";

/// @title LibBytes
/// @notice Tools for working directly with memory in a Solidity compatible way.
library LibBytes {
    /// Truncates bytes of data by mutating its length directly.
    /// Any excess bytes are leaked.
    /// Reverts with `OutOfBoundsTruncate(data.length, length)` if `length` is
    /// greater than `data.length`. Truncation can only shrink.
    /// @param data The bytes to truncate. MUTATED in place, so there is no
    /// return value and no new allocation.
    /// @param length The new length of `data` after truncation. MUST NOT be
    /// greater than `data.length`.
    function truncate(bytes memory data, uint256 length) internal pure {
        if (data.length < length) {
            revert OutOfBoundsTruncate(data.length, length);
        }
        assembly ("memory-safe") {
            mstore(data, length)
        }
    }

    /// Pointer to the data of a bytes array NOT the length prefix.
    /// @param data Bytes to get the data pointer for.
    /// @return pointer Pointer to the data of the bytes in memory.
    function dataPointer(bytes memory data) internal pure returns (Pointer pointer) {
        assembly ("memory-safe") {
            pointer := add(data, 0x20)
        }
    }

    /// Pointer to the start of a bytes array (the length prefix).
    /// @param data Bytes to get the pointer to.
    /// @return pointer Pointer to the start of the bytes data structure.
    function startPointer(bytes memory data) internal pure returns (Pointer pointer) {
        assembly ("memory-safe") {
            pointer := data
        }
    }

    /// Pointer to the end of some bytes.
    ///
    /// Note that this pointer MAY NOT BE ALIGNED, i.e. it MAY NOT point to the
    /// start of a multiple of 32, UNLIKE the free memory pointer at 0x40.
    ///
    /// @param data Bytes to get the pointer to the end of.
    /// @return pointer Pointer to the first byte after the `length` bytes of
    /// data, i.e. NOT including the word alignment padding. Use
    /// `endAllocatedPointer` for the end of the word aligned region.
    function endDataPointer(bytes memory data) internal pure returns (Pointer pointer) {
        assembly ("memory-safe") {
            pointer := add(data, add(0x20, mload(data)))
        }
    }

    /// Pointer to the end of the word aligned region implied by the CURRENT
    /// length of some bytes.
    ///
    /// The allocator is ALWAYS aligned to whole words, i.e. 32 byte multiples,
    /// for data structures allocated by Solidity. This includes `bytes` which
    /// means that any time the length of some `bytes` is NOT a multiple of 32
    /// the allocation will point past the end of the `bytes` data.
    ///
    /// This is the end of the memory Solidity allocated only while the length
    /// word is the one Solidity wrote. `truncate` mutates the length word and
    /// leaks the tail, so after a truncation this pointer is BELOW the end of
    /// the real allocation by the size of the leaked region.
    ///
    /// There is no guarantee that the memory region between `endDataPointer`
    /// and `endAllocatedPointer` is zeroed out. It is best to think of that
    /// space as leaked garbage.
    ///
    /// Almost always, e.g. for the purpose of copying data between regions, you
    /// will want `endDataPointer` rather than this function.
    /// @param data Bytes to get the end of the word aligned region for.
    /// @return pointer Pointer to the end of the word aligned region implied by
    /// the current length.
    function endAllocatedPointer(bytes memory data) internal pure returns (Pointer pointer) {
        assembly ("memory-safe") {
            pointer := add(data, and(add(add(mload(data), 0x20), 0x1f), not(0x1f)))
        }
    }
}

dependencies/rain-solmem-0.1.28/src/lib/LibPointer.sol

// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// A pointer to a location in memory. This is a `uint256` to save gas on low
/// level operations on the evm stack. These same low level operations typically
/// WILL NOT check for overflow or underflow, so all pointer logic MUST ensure
/// that reads, writes and movements are not out of bounds.
type Pointer is uint256;

/// @title LibPointer
/// @notice Ergonomic wrappers around common pointer movements, reads and
/// writes. Every wrapper is a function call, so each one costs jump overhead
/// that inlined assembly does not.
library LibPointer {
    /// Cast a `Pointer` to `bytes` without modification or any safety checks.
    /// The caller MUST ensure the pointer is to a valid region of memory for
    /// some `bytes`.
    /// @param pointer The pointer to cast to `bytes`.
    /// @return data The cast `bytes`.
    function unsafeAsBytes(Pointer pointer) internal pure returns (bytes memory data) {
        assembly ("memory-safe") {
            data := pointer
        }
    }

    /// Increase some pointer by a number of bytes.
    ///
    /// This is UNSAFE because it can silently overflow or point beyond some
    /// data structure. The caller MUST ensure that this is a safe operation.
    ///
    /// Note that moving a pointer by some bytes offset is likely to unalign it
    /// with the 32 byte increments of the Solidity allocator.
    ///
    /// @param pointer The pointer to increase by `length`.
    /// @param length The number of bytes to increase the pointer by.
    /// @return The increased pointer.
    function unsafeAddBytes(Pointer pointer, uint256 length) internal pure returns (Pointer) {
        assembly ("memory-safe") {
            pointer := add(pointer, length)
        }
        return pointer;
    }

    /// Increase some pointer by a single 32 byte word.
    ///
    /// This is UNSAFE because it can silently overflow or point beyond some
    /// data structure. The caller MUST ensure that this is a safe operation.
    ///
    /// If the original pointer is aligned to the Solidity allocator it will be
    /// aligned after the movement.
    ///
    /// @param pointer The pointer to increase by a single word.
    /// @return The increased pointer.
    function unsafeAddWord(Pointer pointer) internal pure returns (Pointer) {
        assembly ("memory-safe") {
            pointer := add(pointer, 0x20)
        }
        return pointer;
    }

    /// Increase some pointer by multiple 32 byte words.
    ///
    /// This is UNSAFE because it can silently overflow or point beyond some
    /// data structure. The caller MUST ensure that this is a safe operation.
    ///
    /// If the original pointer is aligned to the Solidity allocator it will be
    /// aligned after the movement.
    ///
    /// @param pointer The pointer to increase.
    /// @param words The number of words to increase the pointer by.
    /// @return The increased pointer.
    function unsafeAddWords(Pointer pointer, uint256 words) internal pure returns (Pointer) {
        assembly ("memory-safe") {
            pointer := add(pointer, mul(0x20, words))
        }
        return pointer;
    }

    /// Decrease some pointer by a single 32 byte word.
    ///
    /// This is UNSAFE because it can silently underflow or point below some
    /// data structure. The caller MUST ensure that this is a safe operation.
    ///
    /// If the original pointer is aligned to the Solidity allocator it will be
    /// aligned after the movement.
    ///
    /// @param pointer The pointer to decrease by a single word.
    /// @return The decreased pointer.
    function unsafeSubWord(Pointer pointer) internal pure returns (Pointer) {
        assembly ("memory-safe") {
            pointer := sub(pointer, 0x20)
        }
        return pointer;
    }

    /// Decrease some pointer by multiple 32 byte words.
    ///
    /// This is UNSAFE because it can silently underflow or point below some
    /// data structure. The caller MUST ensure that this is a safe operation.
    ///
    /// If the original pointer is aligned to the Solidity allocator it will be
    /// aligned after the movement.
    ///
    /// @param pointer The pointer to decrease.
    /// @param words The number of words to decrease the pointer by.
    /// @return The decreased pointer.
    function unsafeSubWords(Pointer pointer, uint256 words) internal pure returns (Pointer) {
        assembly ("memory-safe") {
            pointer := sub(pointer, mul(0x20, words))
        }
        return pointer;
    }

    /// Read the word at the pointer.
    ///
    /// This is UNSAFE because it can read outside any particular data structure
    /// or even beyond allocated memory. The caller MUST ensure that this is a
    /// safe operation.
    ///
    /// @param pointer Pointer to read the word at.
    /// @return word The word read from the pointer.
    function unsafeReadWord(Pointer pointer) internal pure returns (bytes32 word) {
        assembly ("memory-safe") {
            word := mload(pointer)
        }
    }

    /// Write a word at the pointer.
    ///
    /// This is UNSAFE because it can write outside any particular data structure
    /// or even beyond allocated memory. The caller MUST ensure that this is a
    /// safe operation.
    ///
    /// @param pointer Pointer to write the word at.
    /// @param word The word to write.
    function unsafeWriteWord(Pointer pointer, bytes32 word) internal pure {
        assembly ("memory-safe") {
            mstore(pointer, word)
        }
    }

    /// Get the pointer to the end of all allocated memory.
    /// As per Solidity docs, there is no guarantee that the region of memory
    /// beyond this pointer is zeroed out, as assembly MAY write beyond allocated
    /// memory for temporary use if the scratch space is insufficient.
    /// @return pointer The pointer to the end of all allocated memory.
    function allocatedMemoryPointer() internal pure returns (Pointer pointer) {
        assembly ("memory-safe") {
            pointer := mload(0x40)
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 100000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin-contracts-5.7.0/=dependencies/@openzeppelin-contracts-5.7.0/",
    "forge-std-1.17.0/=dependencies/forge-std-1.17.0/",
    "rain-deploy-0.1.22/=dependencies/rain-deploy-0.1.22/",
    "rain-extrospection-0.1.14/=dependencies/rain-extrospection-0.1.14/",
    "rain-factory-0.2.5/=dependencies/rain-factory-0.2.5/",
    "rain-sol-codegen-0.1.39/=dependencies/rain-sol-codegen-0.1.39/",
    "rain-solmem-0.1.28/=dependencies/rain-solmem-0.1.28/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.