Skip to content
Verified contractExactMIT

FacetEthscriptionBridgeV7

Address0x5ddf2bdc128d1940a5a7f385f6d2eb744ba828be
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,401,339
Creation transaction
0xcc2d3dfaeb…a8b1c775f2

src/shutdown/FacetEthscriptionBridgeV7.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title FacetEthscriptionBridgeV7 — terminal implementation for the Ethscriptions bridges
/// @notice Replaces the signer-operated bridge behind the SAME proxy (the proxy address owns the
///         ethscriptions). After `finalize`, the contract is a permissionless claim distributor:
///           - `claim`: anyone submits a committed leaf (recipient, ids) with a Merkle proof; the
///             ethscriptions are released to the committed recipient via ESIP-1 events, once.
///           - unconfirmed deposits (non-zero `pendingDepositHash`) are settled INSIDE the claim tree, for the IDs
///             the deposit actually delivered, and every known hash is cleared at `finalize`. There is deliberately
///             no self-service recovery path: deposit calldata is unverified — it can list inscriptions the sender
///             never owned, or ones they had already deposited and been credited for — so releasing "the list behind
///             the hash" would hand out other users' backing or pay a depositor twice.
///         No sweep, no expiry, no mutable root, no admin function after finalize (the admin field itself is kept).
///         Proxy upgrade authority is a different thing: the ERC1967Factory admin of each proxy (the Facet
///         multisig) is RETAINED (team decision, 2026-10-20): the multisig keeps the ability to upgrade these
///         proxies in case a correction is ever needed, exactly as it can today. Claims need no action from it;
///         the contract is not immutable against an upgrade by that admin, so nothing may describe it as such.
/// @dev Storage: keeps `BridgeStorage` at its V6 slot (we read `pendingDepositHash`,
///      `processedWithdrawalIds` and flip the legacy flags off). New state lives in its own slot.
contract FacetEthscriptionBridgeV7 {
    /// @dev Solady ERC1967Factory (the proxies' upgrade authority).
    address public constant FACTORY = 0x0000000000006396FF2a80c067f99B3d2Ab4Df24;

    // ---- Ethscriptions protocol events
    event ethscriptions_protocol_TransferEthscription(address indexed recipient, bytes32 indexed id);

    event Finalized(bytes32 claimRoot, uint256 leafCount, uint256 l1Block, bytes32 l1Hash, uint256 facetBlock, string dataURI);
    event SettledDepositorsCleared(uint256 count);
    event Claimed(uint256 indexed leafIndex, address indexed recipient, uint256 count);

    error NotAdmin();
    error AlreadyFinalized();
    error NotFinalized();
    error InvalidProof();
    error AlreadyClaimed();
    error LeafIndexOutOfRange();
    error EmptyIds();
    error LegacyPathRetired();
    error ZeroAddress();

    // ---- V6 storage (layout preserved; see FacetEthscriptionBridgeV6.BridgeStorage)
    struct BridgeStorage {
        mapping(bytes32 => bool) processedWithdrawalIds;
        bool depositEnabled;
        bool withdrawEnabled;
        address adminAddress;
        address signerAddress;
        address dumbContractAddress;
        uint256 cancelBlockNumber;
        mapping(address => bytes32[]) pendingDeposits;
        mapping(bytes32 => bool) processedDepositIds;
        uint256 withdrawDelay;
        address controlledBridge;
        mapping(address => bytes32) pendingDepositHash;
        mapping(bytes32 => mapping(bytes32 => bool)) processedWithdrawalsPerDeposit;
        uint16 bridgeInLimit;
    }

    function s() internal pure returns (BridgeStorage storage cs) {
        bytes32 position = keccak256("BridgeStorage.contract.storage.v1");
        assembly { cs.slot := position }
    }

    // ---- V7 settlement storage
    struct SettlementStorage {
        bool finalized;
        bytes32 claimRoot;          // keccak(abi.encode(leafIndex, recipient, ids[]))
        uint256 leafCount;
        uint256 snapshotL1Block;
        bytes32 snapshotL1Hash;
        uint256 snapshotFacetBlock;
        string dataURI;             // where the full allocation + proofs are published
        mapping(uint256 => uint256) claimedBitmap;
        uint256 claimedLeaves;
        uint256 releasedCount;
    }

    function t() internal pure returns (SettlementStorage storage cs) {
        bytes32 position = keccak256("FacetEthscriptionBridge.settlement.v1");
        assembly { cs.slot := position }
    }

    // ------------------------------------------------------------------ finalize (one shot)
    /// @notice Commits the claim root and retires every legacy path. Intended to be the
    ///         `upgradeAndCall` payload. Callable once, by the legacy bridge admin.
    function finalize(
        bytes32 claimRoot,
        uint256 leafCount,
        uint256 l1Block,
        bytes32 l1Hash,
        uint256 facetBlock,
        string calldata dataURI,
        address[] calldata settledDepositors
    ) external {
        // Reached either directly by the legacy bridge admin, or as the `upgradeAndCall` payload, in
        // which case msg.sender is the ERC1967Factory (only the proxy's factory admin can trigger that).
        if (msg.sender != s().adminAddress && msg.sender != FACTORY) revert NotAdmin();
        if (t().finalized) revert AlreadyFinalized();
        if (claimRoot == bytes32(0) || leafCount == 0) revert InvalidProof();

        SettlementStorage storage st = t();
        st.finalized = true;
        st.claimRoot = claimRoot;
        st.leafCount = leafCount;
        st.snapshotL1Block = l1Block;
        st.snapshotL1Hash = l1Hash;
        st.snapshotFacetBlock = facetBlock;
        st.dataURI = dataURI;

        // retire the signer-operated paths for good
        BridgeStorage storage bs = s();
        bs.depositEnabled = false;
        bs.withdrawEnabled = false;
        bs.cancelBlockNumber = type(uint256).max; // every outstanding signature is void
        bs.signerAddress = address(0);
        // adminAddress is kept (team decision): no function in this implementation is gated by it after finalize,
        // and a later implementation installed by the proxy admin may want it in place

        // every depositor whose unconfirmed deposit the reconciliation settled (owed IDs are in the tree, or the
        // deposit delivered nothing): clear the hash so no stale "pending" state survives
        for (uint256 i; i < settledDepositors.length; ++i) {
            delete bs.pendingDepositHash[settledDepositors[i]];
        }

        emit Finalized(claimRoot, leafCount, l1Block, l1Hash, facetBlock, dataURI);
        emit SettledDepositorsCleared(settledDepositors.length);
    }

    // ------------------------------------------------------------------ claims
    /// @notice Release a committed allocation. Anyone may submit; delivery is to the committed recipient.
    function claim(uint256 leafIndex, address recipient, bytes32[] calldata ids, bytes32[] calldata proof) external {
        SettlementStorage storage st = t();
        if (!st.finalized) revert NotFinalized();
        if (leafIndex >= st.leafCount) revert LeafIndexOutOfRange();
        if (ids.length == 0) revert EmptyIds();
        if (recipient == address(0)) revert ZeroAddress();

        bytes32 leaf = keccak256(abi.encode(leafIndex, recipient, ids));
        if (!_verify(st.claimRoot, leaf, proof)) revert InvalidProof();

        uint256 word = leafIndex >> 8;
        uint256 bit = 1 << (leafIndex & 255);
        uint256 v = st.claimedBitmap[word];
        if (v & bit != 0) revert AlreadyClaimed();
        st.claimedBitmap[word] = v | bit;
        st.claimedLeaves += 1;
        st.releasedCount += ids.length;

        for (uint256 i; i < ids.length; ++i) {
            emit ethscriptions_protocol_TransferEthscription(recipient, ids[i]);
        }
        emit Claimed(leafIndex, recipient, ids.length);
    }

    // ------------------------------------------------------------------ views
    function isClaimed(uint256 leafIndex) external view returns (bool) {
        return t().claimedBitmap[leafIndex >> 8] & (1 << (leafIndex & 255)) != 0;
    }

    function settlement() external view returns (
        bool finalized, bytes32 claimRoot, uint256 leafCount, uint256 l1Block, bytes32 l1Hash,
        uint256 facetBlock, string memory dataURI, uint256 claimedLeaves, uint256 releasedCount
    ) {
        SettlementStorage storage st = t();
        return (st.finalized, st.claimRoot, st.leafCount, st.snapshotL1Block, st.snapshotL1Hash,
                st.snapshotFacetBlock, st.dataURI, st.claimedLeaves, st.releasedCount);
    }

    function getPendingDepositHash(address sender) external view returns (bytes32) { return s().pendingDepositHash[sender]; }
    function processedWithdraws(bytes32 withdrawalId) external view returns (bool) { return s().processedWithdrawalIds[withdrawalId]; }
    function getDepositEnabled() external view returns (bool) { return s().depositEnabled; }
    function getWithdrawalEnabled() external view returns (bool) { return s().withdrawEnabled; }
    function getAdmin() external view returns (address) { return s().adminAddress; }
    function getSigner() external view returns (address) { return s().signerAddress; }
    function getCancelBlockNumber() external view returns (uint256) { return s().cancelBlockNumber; }

    /// @dev Legacy deposit entry point (raw concatenated IDs). Retired: new deposits are refused.
    fallback() external { revert LegacyPathRetired(); }

    // ------------------------------------------------------------------ merkle
    function _verify(bytes32 root, bytes32 leaf, bytes32[] calldata proof) internal pure returns (bool) {
        bytes32 h = leaf;
        for (uint256 i; i < proof.length; ++i) {
            bytes32 p = proof[i];
            h = h <= p ? keccak256(abi.encodePacked(h, p)) : keccak256(abi.encodePacked(p, h));
        }
        return h == root;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "solady/src/=lib/solady/src/",
    "facet-sol/src/=lib/facet-sol/src/",
    "lib/facet-sol/:forge-std/=lib/facet-sol/lib/forge-std/src/",
    "lib/facet-sol/:solady/src/=lib/solady/src/",
    "lib/facet-sol/:solady/=lib/facet-sol/lib/solady/src/",
    "lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "facet-sol/=lib/facet-sol/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solady/=lib/solady/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.