Skip to content
Verified contractPartialGPL-3.0-only

ZZonesRegistry

Address0xf87ab51098bb4e3d44f0695b5d1ff0af7c84f9d1
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.19

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
Yes, 800 runs
License
GPL-3.0-only
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,882,662
Creation transaction
0x4eb2217ad7…9cd013f2cd
Libraries
contracts/contracts/protocol/v1/trees/facets/ZZonesRegistry.sol:PoseidonT30xd98c…30fb41

contracts/contracts/protocol/v1/trees/facets/ZZonesRegistry.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

import "../storage/AppStorage.sol";
import "../storage/ZZonesRegistryStorageGap.sol";

import "./staticTrees/StaticRootUpdater.sol";

import "../../diamond/utils/Ownable.sol";
import "../utils/merkleTrees/BinaryUpdatableTree.sol";

import { ZZONE_STATIC_LEAF_INDEX } from "../utils/Constants.sol";
import { SIXTEEN_LEVEL_EMPTY_TREE_ROOT, SIXTEEN_LEVELS } from "../utils/zeroTrees/Constants.sol";

import "../../../../common/crypto/PoseidonHashers.sol";

/**
 * @title ZNetworksRegistry
 * @author Pantherprotocol Contributors
 * @notice Registry and whitelist of assets (tokens) supported by the Panther
 * Protocol Multi-Asset Shielded Pool (aka "MASP")
 */

contract ZZonesRegistry is
    AppStorage,
    ZZonesRegistryStorageGap,
    StaticRootUpdater,
    Ownable,
    BinaryUpdatableTree
{
    // The current root of merkle tree.
    // If it's undefined, the `zeroRoot()` shall be called.
    bytes32 private _currentRoot;

    event ZZonesTreeUpdated(bytes32 newRoot);

    constructor(address self) StaticRootUpdater(self) {}

    function getZZonesRoot() public view returns (bytes32) {
        return _currentRoot == bytes32(0) ? zeroRoot() : _currentRoot;
    }

    function addZone(
        bytes32 curLeaf,
        bytes32 newLeaf,
        uint256 leafIndex,
        bytes32[] calldata proofSiblings
    ) external onlyOwner {
        require(proofSiblings.length == SIXTEEN_LEVELS, "invalid proof length");

        bytes32 zZonesTreeRoot = update(
            getZZonesRoot(),
            curLeaf,
            newLeaf,
            leafIndex,
            proofSiblings
        );

        // Trusted contract - no reentrancy guard needed
        _updateStaticRoot(zZonesTreeRoot, ZZONE_STATIC_LEAF_INDEX);

        _currentRoot = zZonesTreeRoot;

        emit ZZonesTreeUpdated(zZonesTreeRoot);
    }

    //@dev returns the root of tree with depth 16 where each leaf is ZERO_VALUE
    function zeroRoot() internal pure override returns (bytes32) {
        return SIXTEEN_LEVEL_EMPTY_TREE_ROOT;
    }

    function hash(
        bytes32[2] memory input
    ) internal pure override returns (bytes32) {
        return PoseidonHashers.poseidonT3(input);
    }
}

contracts/contracts/common/crypto/Poseidon.sol

// SPDX-License-Identifier: MIT
// solhint-disable one-contract-per-file
pragma solidity ^0.8.16;

// This is a stub to keep solc happy; the actual code is generated
// using poseidon_gencontract.js from circomlibjs.

library PoseidonT3 {
    function poseidon(bytes32[2] memory input) external pure returns (bytes32) {
        require(input.length == 99, "FAKE"); // always reverts
        return 0;
    }
}

library PoseidonT4 {
    function poseidon(bytes32[3] memory input) external pure returns (bytes32) {
        require(input.length == 99, "FAKE"); // always reverts
        return 0;
    }
}

library PoseidonT5 {
    function poseidon(bytes32[4] memory input) external pure returns (bytes32) {
        require(input.length == 99, "FAKE"); // always reverts
        return 0;
    }
}

library PoseidonT6 {
    function poseidon(bytes32[5] memory input) external pure returns (bytes32) {
        require(input.length == 99, "FAKE"); // always reverts
        return 0;
    }
}

contracts/contracts/common/crypto/PoseidonHashers.sol

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.16;

import { FIELD_SIZE } from "./SnarkConstants.sol";
import "./Poseidon.sol";

library PoseidonHashers {
    string private constant ERR_INPUT_NOT_IN_FIELD =
        "PoseidonHasher: input not in field";

    function poseidonT3(
        bytes32[2] memory input
    ) internal pure returns (bytes32) {
        require(
            uint256(input[0]) < FIELD_SIZE && uint256(input[1]) < FIELD_SIZE,
            ERR_INPUT_NOT_IN_FIELD
        );
        return PoseidonT3.poseidon(input);
    }

    function poseidonT4(
        bytes32[3] memory input
    ) internal pure returns (bytes32) {
        require(
            uint256(input[0]) < FIELD_SIZE &&
                uint256(input[1]) < FIELD_SIZE &&
                uint256(input[2]) < FIELD_SIZE,
            ERR_INPUT_NOT_IN_FIELD
        );
        return PoseidonT4.poseidon(input);
    }

    function poseidonT5(
        bytes32[4] memory input
    ) internal pure returns (bytes32) {
        require(
            uint256(input[0]) < FIELD_SIZE &&
                uint256(input[1]) < FIELD_SIZE &&
                uint256(input[2]) < FIELD_SIZE &&
                uint256(input[3]) < FIELD_SIZE,
            ERR_INPUT_NOT_IN_FIELD
        );
        return PoseidonT5.poseidon(input);
    }

    function poseidonT6(
        bytes32[5] memory input
    ) internal pure returns (bytes32) {
        require(
            uint256(input[0]) < FIELD_SIZE &&
                uint256(input[1]) < FIELD_SIZE &&
                uint256(input[2]) < FIELD_SIZE &&
                uint256(input[3]) < FIELD_SIZE &&
                uint256(input[4]) < FIELD_SIZE,
            ERR_INPUT_NOT_IN_FIELD
        );
        return PoseidonT6.poseidon(input);
    }
}

contracts/contracts/common/crypto/SnarkConstants.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.16;

// @dev Order of alt_bn128 and the field prime of Baby Jubjub and Poseidon hash
uint256 constant FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

// @dev Field prime of alt_bn128
uint256 constant PRIME_Q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;

contracts/contracts/protocol/v1/diamond/interfaces/IDiamondCut.sol

// SPDX-License-Identifier: MIT
// solhint-disable compiler-version
pragma solidity ^0.8.0;

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

interface IDiamondCut {
    enum FacetCutAction {
        Add,
        Replace,
        Remove
    }
    // Add=0, Replace=1, Remove=2

    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    /// @notice Add/replace/remove any number of functions and optionally execute
    ///         a function with delegatecall
    /// @param _diamondCut Contains the facet addresses and function selectors
    /// @param _init The address of the contract or facet to execute _calldata
    /// @param _calldata A function call, including function selector and arguments
    ///                  _calldata is executed with delegatecall on _init
    function diamondCut(
        FacetCut[] calldata _diamondCut,
        address _init,
        bytes calldata _calldata
    ) external;

    event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
}

contracts/contracts/protocol/v1/diamond/libraries/LibDiamond.sol

// SPDX-License-Identifier: MIT
// solhint-disable code-complexity
// solhint-disable compiler-version
// solhint-disable state-visibility
// solhint-disable no-inline-assembly
// solhint-disable avoid-low-level-calls
pragma solidity ^0.8.0;

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
import { IDiamondCut } from "../interfaces/IDiamondCut.sol";

// Remember to add the loupe functions from DiamondLoupeFacet to the diamond.
// The loupe functions are required by the EIP2535 Diamonds standard

error InitializationFunctionReverted(
    address _initializationContractAddress,
    bytes _calldata
);

library LibDiamond {
    bytes32 constant DIAMOND_STORAGE_POSITION =
        keccak256("diamond.standard.diamond.storage");

    // keccak256("owner.position");
    bytes32 constant OWNER_POSITION =
        0x727bf440e01434e77993b7e90f004fc30e73d97686694c4ace34badd87948d44;

    // keccak256("reentrancy.status.position");
    bytes32 constant REENTRANCY_STATUS_POSITION =
        0xa2d689582372faaaa3b92103e3057ffde86663fa2f4d2f6c8f9da8a22702278d;

    struct DiamondStorage {
        // maps function selectors to the facets that execute the functions.
        // and maps the selectors to their position in the selectorSlots array.
        // func selector => address facet, selector position
        mapping(bytes4 => bytes32) facets;
        // array of slots of function selectors.
        // each slot holds 8 function selectors.
        mapping(uint256 => bytes32) selectorSlots;
        // The number of function selectors in selectorSlots
        uint16 selectorCount;
        // Used to query if a contract implements an interface.
        // Used to implement ERC-165.
        mapping(bytes4 => bool) supportedInterfaces;
    }

    function diamondStorage()
        internal
        pure
        returns (DiamondStorage storage ds)
    {
        bytes32 position = DIAMOND_STORAGE_POSITION;
        assembly {
            ds.slot := position
        }
    }

    function reentrancyStatus()
        internal
        view
        returns (uint256 _reentrancyStatus)
    {
        bytes32 position = REENTRANCY_STATUS_POSITION;
        assembly {
            _reentrancyStatus := sload(position)
        }
    }

    function setReentrancyStatus(uint256 status) internal {
        assembly {
            sstore(REENTRANCY_STATUS_POSITION, status)
        }
    }

    function owner() internal view returns (address _owner) {
        bytes32 position = OWNER_POSITION;
        assembly {
            _owner := sload(position)
        }
    }

    event OwnershipUpdated(address owner);

    function setContractOwner(address _owner) internal {
        assembly {
            sstore(OWNER_POSITION, _owner)
        }
        emit OwnershipUpdated(_owner);
    }

    function enforceOwner() internal view {
        require(msg.sender == owner(), "LibDiamond: Must be contract owner");
    }

    event DiamondCut(
        IDiamondCut.FacetCut[] _diamondCut,
        address _init,
        bytes _calldata
    );

    bytes32 constant CLEAR_ADDRESS_MASK =
        bytes32(uint256(0xffffffffffffffffffffffff));
    bytes32 constant CLEAR_SELECTOR_MASK = bytes32(uint256(0xffffffff << 224));

    // Internal function version of diamondCut
    // This code is almost the same as the external diamondCut,
    // except it is using 'Facet[] memory _diamondCut' instead of
    // 'Facet[] calldata _diamondCut'.
    // The code is duplicated to prevent copying calldata to memory which
    // causes an error for a two dimensional array.
    function diamondCut(
        IDiamondCut.FacetCut[] memory _diamondCut,
        address _init,
        bytes memory _calldata
    ) internal {
        DiamondStorage storage ds = diamondStorage();
        uint256 originalSelectorCount = ds.selectorCount;
        uint256 selectorCount = originalSelectorCount;
        bytes32 selectorSlot;
        // Check if last selector slot is not full
        // "selectorCount & 7" is a gas efficient modulo by eight "selectorCount % 8"
        if (selectorCount & 7 > 0) {
            // get last selectorSlot
            // "selectorSlot >> 3" is a gas efficient division by 8 "selectorSlot / 8"
            selectorSlot = ds.selectorSlots[selectorCount >> 3];
        }
        // loop through diamond cut
        for (uint256 facetIndex; facetIndex < _diamondCut.length; ) {
            (selectorCount, selectorSlot) = addReplaceRemoveFacetSelectors(
                selectorCount,
                selectorSlot,
                _diamondCut[facetIndex].facetAddress,
                _diamondCut[facetIndex].action,
                _diamondCut[facetIndex].functionSelectors
            );

            unchecked {
                facetIndex++;
            }
        }
        if (selectorCount != originalSelectorCount) {
            ds.selectorCount = uint16(selectorCount);
        }
        // If last selector slot is not full
        // "selectorCount & 7" is a gas efficient modulo by eight "selectorCount % 8"
        if (selectorCount & 7 > 0) {
            // "selectorSlot >> 3" is a gas efficient division by 8 "selectorSlot / 8"
            ds.selectorSlots[selectorCount >> 3] = selectorSlot;
        }
        emit DiamondCut(_diamondCut, _init, _calldata);
        initializeDiamondCut(_init, _calldata);
    }

    function addReplaceRemoveFacetSelectors(
        uint256 _selectorCount,
        bytes32 _selectorSlot,
        address _newFacetAddress,
        IDiamondCut.FacetCutAction _action,
        bytes4[] memory _selectors
    ) internal returns (uint256, bytes32) {
        DiamondStorage storage ds = diamondStorage();
        require(
            _selectors.length > 0,
            "LibDiamondCut: No selectors in facet to cut"
        );
        if (_action == IDiamondCut.FacetCutAction.Add) {
            enforceHasContractCode(
                _newFacetAddress,
                "LibDiamondCut: Add facet has no code"
            );
            for (uint256 selectorIndex; selectorIndex < _selectors.length; ) {
                bytes4 selector = _selectors[selectorIndex];
                bytes32 oldFacet = ds.facets[selector];
                require(
                    address(bytes20(oldFacet)) == address(0),
                    "LibDiamondCut: Can't add function that already exists"
                );
                // add facet for selector
                ds.facets[selector] =
                    bytes20(_newFacetAddress) |
                    bytes32(_selectorCount);
                // "_selectorCount & 7" is a gas efficient modulo by eight "_selectorCount % 8"
                // " << 5 is the same as multiplying by 32 ( * 32)
                uint256 selectorInSlotPosition = (_selectorCount & 7) << 5;
                // clear selector position in slot and add selector
                _selectorSlot =
                    (_selectorSlot &
                        ~(CLEAR_SELECTOR_MASK >> selectorInSlotPosition)) |
                    (bytes32(selector) >> selectorInSlotPosition);
                // if slot is full then write it to storage
                if (selectorInSlotPosition == 224) {
                    // "_selectorSlot >> 3" is a gas efficient division by 8 "_selectorSlot / 8"
                    ds.selectorSlots[_selectorCount >> 3] = _selectorSlot;
                    _selectorSlot = 0;
                }
                _selectorCount++;

                unchecked {
                    selectorIndex++;
                }
            }
        } else if (_action == IDiamondCut.FacetCutAction.Replace) {
            enforceHasContractCode(
                _newFacetAddress,
                "LibDiamondCut: Replace facet has no code"
            );
            for (uint256 selectorIndex; selectorIndex < _selectors.length; ) {
                bytes4 selector = _selectors[selectorIndex];
                bytes32 oldFacet = ds.facets[selector];
                address oldFacetAddress = address(bytes20(oldFacet));
                // only useful if immutable functions exist
                require(
                    oldFacetAddress != address(this),
                    "LibDiamondCut: Can't replace immutable function"
                );
                require(
                    oldFacetAddress != _newFacetAddress,
                    "LibDiamondCut: Can't replace function with same function"
                );
                require(
                    oldFacetAddress != address(0),
                    "LibDiamondCut: Can't replace function that doesn't exist"
                );
                // replace old facet address
                ds.facets[selector] =
                    (oldFacet & CLEAR_ADDRESS_MASK) |
                    bytes20(_newFacetAddress);

                unchecked {
                    selectorIndex++;
                }
            }
        } else if (_action == IDiamondCut.FacetCutAction.Remove) {
            require(
                _newFacetAddress == address(0),
                "LibDiamondCut: Remove facet address must be address(0)"
            );
            // "_selectorCount >> 3" is a gas efficient division by 8 "_selectorCount / 8"
            uint256 selectorSlotCount = _selectorCount >> 3;
            // "_selectorCount & 7" is a gas efficient modulo by eight "_selectorCount % 8"
            uint256 selectorInSlotIndex = _selectorCount & 7;
            for (uint256 selectorIndex; selectorIndex < _selectors.length; ) {
                if (selectorInSlotIndex == 0) {
                    // get last selectorSlot
                    selectorSlotCount--;
                    _selectorSlot = ds.selectorSlots[selectorSlotCount];
                    selectorInSlotIndex = 7;
                } else {
                    selectorInSlotIndex--;
                }
                bytes4 lastSelector;
                uint256 oldSelectorsSlotCount;
                uint256 oldSelectorInSlotPosition;
                // adding a block here prevents stack too deep error
                {
                    bytes4 selector = _selectors[selectorIndex];
                    bytes32 oldFacet = ds.facets[selector];
                    require(
                        address(bytes20(oldFacet)) != address(0),
                        "LibDiamondCut: Can't remove function that doesn't exist"
                    );
                    // only useful if immutable functions exist
                    require(
                        address(bytes20(oldFacet)) != address(this),
                        "LibDiamondCut: Can't remove immutable function"
                    );
                    // replace selector with last selector in ds.facets
                    // gets the last selector
                    // " << 5 is the same as multiplying by 32 ( * 32)
                    lastSelector = bytes4(
                        _selectorSlot << (selectorInSlotIndex << 5)
                    );
                    if (lastSelector != selector) {
                        // update last selector slot position info
                        ds.facets[lastSelector] =
                            (oldFacet & CLEAR_ADDRESS_MASK) |
                            bytes20(ds.facets[lastSelector]);
                    }
                    delete ds.facets[selector];
                    uint256 oldSelectorCount = uint16(uint256(oldFacet));
                    // "oldSelectorCount >> 3" is a gas efficient division by 8 "oldSelectorCount / 8"
                    oldSelectorsSlotCount = oldSelectorCount >> 3;
                    // "oldSelectorCount & 7" is a gas efficient modulo by eight "oldSelectorCount % 8"
                    // " << 5 is the same as multiplying by 32 ( * 32)
                    oldSelectorInSlotPosition = (oldSelectorCount & 7) << 5;
                }
                if (oldSelectorsSlotCount != selectorSlotCount) {
                    bytes32 oldSelectorSlot = ds.selectorSlots[
                        oldSelectorsSlotCount
                    ];
                    // clears the selector we are deleting and puts the last selector in its place.
                    oldSelectorSlot =
                        (oldSelectorSlot &
                            ~(CLEAR_SELECTOR_MASK >>
                                oldSelectorInSlotPosition)) |
                        (bytes32(lastSelector) >> oldSelectorInSlotPosition);
                    // update storage with the modified slot
                    ds.selectorSlots[oldSelectorsSlotCount] = oldSelectorSlot;
                } else {
                    // clears the selector we are deleting and puts the last selector in its place.
                    _selectorSlot =
                        (_selectorSlot &
                            ~(CLEAR_SELECTOR_MASK >>
                                oldSelectorInSlotPosition)) |
                        (bytes32(lastSelector) >> oldSelectorInSlotPosition);
                }
                if (selectorInSlotIndex == 0) {
                    delete ds.selectorSlots[selectorSlotCount];
                    _selectorSlot = 0;
                }

                unchecked {
                    selectorIndex++;
                }
            }
            _selectorCount = selectorSlotCount * 8 + selectorInSlotIndex;
        } else {
            revert("LibDiamondCut: Incorrect FacetCutAction");
        }
        return (_selectorCount, _selectorSlot);
    }

    function initializeDiamondCut(
        address _init,
        bytes memory _calldata
    ) internal {
        if (_init == address(0)) {
            return;
        }
        enforceHasContractCode(
            _init,
            "LibDiamondCut: _init address has no code"
        );
        (bool success, bytes memory error) = _init.delegatecall(_calldata);
        if (!success) {
            if (error.length > 0) {
                // bubble up error
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(error)
                    revert(add(32, error), returndata_size)
                }
            } else {
                revert InitializationFunctionReverted(_init, _calldata);
            }
        }
    }

    function enforceHasContractCode(
        address _contract,
        string memory _errorMessage
    ) internal view {
        uint256 contractSize;
        assembly {
            contractSize := extcodesize(_contract)
        }
        require(contractSize > 0, _errorMessage);
    }
}

contracts/contracts/protocol/v1/diamond/utils/Ownable.sol

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

import { LibDiamond } from "../libraries/LibDiamond.sol";

abstract contract Ownable {
    /// @dev Throws if called by any account other than the {OWNER}.
    modifier onlyOwner() virtual {
        LibDiamond.enforceOwner();
        _;
    }
}

contracts/contracts/protocol/v1/trees/facets/staticTrees/StaticRootUpdater.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

import "../../interfaces/IStaticTreeRootUpdater.sol";

abstract contract StaticRootUpdater {
    address private immutable SELF;

    constructor(address self) {
        SELF = self;
    }

    function _updateStaticRoot(bytes32 newRoot, uint256 leafIndex) internal {
        IStaticTreeRootUpdater(SELF).updateStaticRoot(newRoot, leafIndex);
    }
}

contracts/contracts/protocol/v1/trees/interfaces/IStaticTreeRootUpdater.sol

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

interface IStaticTreeRootUpdater {
    function updateStaticRoot(bytes32 updatedLeaf, uint256 leafIndex) external;
}

contracts/contracts/protocol/v1/trees/storage/AppStorage.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation

pragma solidity ^0.8.19;

import { APP_STORAGE_END_GAP } from "./Constants.sol";

abstract contract AppStorage {
    bytes32 internal forestRoot;

    bytes32 internal staticRoot;

    bytes32[APP_STORAGE_END_GAP] private _endGap;
}

contracts/contracts/protocol/v1/trees/storage/Constants.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation

pragma solidity ^0.8.19;

uint256 constant APP_STORAGE_END_GAP = 1e2;

uint256 constant FOREST_TREE_START_GAP = 1e3;
uint256 constant STATIC_TREE_START_GAP = 3e3;
uint256 constant Z_ASSETS_START_GAP = 5e9;
uint256 constant BLACKLISTED_ZACCOUNTS_IDS_START_GAP = 7e3;
uint256 constant Z_NETWORKS_START_GAP = 9e3;
uint256 constant Z_ZONES_START_GAP = 11e3;
uint256 constant PROVIDERS_KEYS_START_GAP = 13e3;

contracts/contracts/protocol/v1/trees/storage/ZZonesRegistryStorageGap.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation

pragma solidity ^0.8.19;

import { Z_ZONES_START_GAP } from "./Constants.sol";

abstract contract ZZonesRegistryStorageGap {
    bytes32[Z_ZONES_START_GAP] private _startGap;
}

contracts/contracts/protocol/v1/trees/utils/Constants.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

// `PantherForest` tree leafs indices (leafs store specific merkle trees roots)
uint256 constant TAXI_TREE_FOREST_LEAF_INDEX = 0;
uint256 constant BUS_TREE_FOREST_LEAF_INDEX = 1;
uint256 constant FERRY_TREE_FOREST_LEAF_INDEX = 2;

// `PantherStaticTree` leafs indices (leafs store specific merkle trees roots)
uint256 constant ZASSET_STATIC_LEAF_INDEX = 0;
uint256 constant BLACKLISTED_ZACCOUNT_STATIC_LEAF_INDEX = 1;
uint256 constant ZNETWORK_STATIC_LEAF_INDEX = 2;
uint256 constant ZZONE_STATIC_LEAF_INDEX = 3;
uint256 constant PROVIDERS_KEYS_STATIC_LEAF_INDEX = 4;

contracts/contracts/protocol/v1/trees/utils/merkleTrees/BinaryUpdatableTree.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

// @notice The "binary binary tree" populated with zero leaf values

/**
 * @title BinaryIncrementalUpdatableMerkleTree
 * @notice
 * @dev
 */
abstract contract BinaryUpdatableTree {
    /**
     * @dev Update an existing leaf
     * @param curRoot current merkle root.
     * @param leaf Leaf to be updated.
     * @param newLeaf New leaf.
     * @param leafIndex leafIndex
     * @param proofSiblings Path of the proof of membership.
     * @return _newRoot The new root after updating the tree
     */
    function update(
        bytes32 curRoot,
        bytes32 leaf,
        bytes32 newLeaf,
        uint256 leafIndex,
        bytes32[] memory proofSiblings
    ) internal pure returns (bytes32 _newRoot) {
        require(newLeaf != leaf, "BIUT: New leaf cannot be equal the old one");
        require(
            verify(curRoot, leaf, leafIndex, proofSiblings),
            "BIUT: Leaf is not part of the tree"
        );

        _newRoot = newLeaf;
        uint256 proofPathIndice;

        // using `proofSiblings[]` length as the tree dept
        for (uint256 i = 0; i < proofSiblings.length; ) {
            // getting the bit at position `i` and check if it's 0 or 1
            proofPathIndice = (leafIndex >> i) & 1;

            if (proofPathIndice == 0) {
                _newRoot = hash([_newRoot, proofSiblings[i]]);
            } else {
                _newRoot = hash([proofSiblings[i], _newRoot]);
            }

            unchecked {
                ++i;
            }
        }
    }

    /**
     * @dev Verify if the path is correct and the leaf is part of the tree.
     * @param curRoot current merkle root.
     * @param leaf Leaf to be updated.
     * @param leafIndex leafIndex
     * @param proofSiblings Path of the proof of membership.
     * @return True or false.
     */
    function verify(
        bytes32 curRoot,
        bytes32 leaf,
        uint256 leafIndex,
        bytes32[] memory proofSiblings
    ) internal pure returns (bool) {
        // equal to 2**proofSiblings.length
        uint256 leavesNum = 1 << proofSiblings.length;
        require(leafIndex < leavesNum, "BIUT: invalid leaf index");

        bytes32 _hash = leaf;
        uint256 proofPathIndice;

        // using `proofSiblings[]` length as the tree dept
        for (uint256 i = 0; i < proofSiblings.length; ) {
            // getting the bit at position `i` and check if it's 0 or 1
            proofPathIndice = (leafIndex >> i) & 1;

            if (proofPathIndice == 0) {
                _hash = hash([_hash, proofSiblings[i]]);
            } else {
                _hash = hash([proofSiblings[i], _hash]);
            }

            unchecked {
                ++i;
            }
        }

        return curRoot == 0 ? _hash == zeroRoot() : _hash == curRoot;
    }

    function zeroRoot() internal pure virtual returns (bytes32);

    function hash(
        bytes32[2] memory input
    ) internal pure virtual returns (bytes32);
}

contracts/contracts/protocol/v1/trees/utils/zeroTrees/Constants.sol

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright 2021-25 Panther Protocol Foundation
pragma solidity ^0.8.19;

/// @dev Leaf zero value (`keccak256("Pantherprotocol")%FIELD_SIZE`)
bytes32 constant ZERO_VALUE = bytes32(
    uint256(0x0667764c376602b72ef22218e1673c2cc8546201f9a77807570b3e5de137680d)
);

// The roots of empty trees follow.
// An "empty" tree is a binary merkle tree of a given number of levels bellow
// the root (depth), fully populated with ZERO_VALUE leafs, with the `poseidon`
// hash function applied.
// (computed by `../../../../lib/binaryMerkleZerosContractGenerator.ts`)

uint256 constant TWO_LEVELS = 2;
/// @dev Root of the binary merkle TWO_LEVELS tree with ZERO_VALUE leafs
// Level 0: ZERO_VALUE
// Level 1: 0x232fc5fea3994c77e07e1bab1ec362727b0f71f291c17c34891dd4faf1457bd4
bytes32 constant TWO_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x077851cf613fd96280795a3cabc89663f524b1b545a3b1c7c79130b0f7d251c8)
);

uint256 constant SIX_LEVELS = 6;
/// @dev Root of the binary merkle SIX_LEVELS tree with ZERO_VALUE leafs
// Level 0: ZERO_VALUE
// Level 1: 0x232fc5fea3994c77e07e1bab1ec362727b0f71f291c17c34891dd4faf1457bd4
// Level 2: 0x077851cf613fd96280795a3cabc89663f524b1b545a3b1c7c79130b0f7d251c8
// Level 3: 0x1d79fd0bc46f7ca934dbcd3386a06f03c43f497851b3815ee726e7f9b26e504c
// Level 4: 0x05c0c15753806f506f64c18bf07116542451822479c4a89305cd4eb7ee94c800
// Level 5: 0x2b56fd5e780ebebdacdd27e6464cf01aac089461a998814974a7504aabb2023f
bytes32 constant SIX_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x2e99dc37b0a4f107b20278c26562b55df197e0b3eb237ec672f4cf729d159b69)
);

uint256 constant EIGHT_LEVELS = 8;
/// @dev Root of the binary merkle EIGHT_LEVELS tree with ZERO_VALUE leafs
// Level 6: SIX_LEVEL_EMPTY_TREE_ROOT
// Level 7: 0x225624653ac89fe211c0c3d303142a4caf24eb09050be08c33af2e7a1e372a0f
bytes32 constant EIGHT_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x276c76358db8af465e2073e4b25d6b1d83f0b9b077f8bd694deefe917e2028d7)
);

uint256 constant SIXTEEN_LEVELS = 16;
/// @dev Root of the binary merkle SIXTEEN_LEVELS tree with ZERO_VALUE leafs
// Level 8:  EIGHT_LEVEL_EMPTY_TREE_ROOT
// Level 9:  0x09df92f4ade78ea54b243914f93c2da33414c22328a73274b885f32aa9dea718
// Level 10: 0x1c78b565f2bfc03e230e0cf12ecc9613ab8221f607d6f6bc2a583ccd690ecc58
// Level 11: 0x2879d62c83d6a3af05c57a4aee11611a03edec5ff8860b07de77968f47ff1c5f
// Level 12: 0x28ad970560de01e93b613aabc930fcaf087114743909783e3770a1ed07c2cde6
// Level 13: 0x27ca60def9dd0603074444029cbcbeaa9dbe77668479ac1db738bb892d9f3b6d
// Level 14: 0x28e4c1e90bbfa69de93abf6cbdc7cd1c0753a128e83b2b3afe34e0471a13ff55
// Level 15: 0x1b89c44a9f153266ad5bf754d4b252c26acba7d21fc661b94dc0618c6a82f49c
bytes32 constant SIXTEEN_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x0a5e5ec37bd8f9a21a1c2192e7c37d86bf975d947c2b38598b00babe567191c9)
);

uint256 constant TWENTY_LEVELS = 20;
/// @dev Root of the merkle binary TWENTY_LEVELS tree with ZERO_VALUE leafs
// Level 16: SIXTEEN_LEVEL_EMPTY_TREE_ROOT
// Level 17: 0x21fb04b171b68944c640020a3a464602ec8d02495c44f1e403d9be4a97128e49
// Level 18: 0x19151c748859974805eb30feac7a301266dec9f67e23e285fe750f86448a2af9
// Level 19: 0x18fb0b755218eaa809681eb87e45925faa9197507d368210d73b5836ebf139e4
bytes32 constant TWENTY_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x1e294375b42dfd97795e07e1fe8bd6cefcb16c3bbb71b30bed950f8965861244)
);

uint256 constant TWENTY_SIX_LEVELS = 26;
/// @dev Root of the binary merkle TWENTY_SIX_LEVELS tree with ZERO_VALUE leafs
// Level 21: 0x0d3e4235db275d9bab0808dd9ade8789d46d0e1f1c9a99ce73fefca51dc92f4a
// Level 22: 0x075ab2ca945c4dc5ea40a9f1c66d5bf3c367cef1e04e73aa17c2bc747eb5fc87
// Level 23: 0x26f0f533a8ea2210001aeb8f8306c7c70656ba6afe145c6540bd4ed2c967a230
// Level 24: 0x24be7e64f680326e6e3621e5862d7b6b1f31e9e183a0bf5dd04e823be84e6af9
// Level 25: 0x212b13c9cbf421942ae3e3c62a3c072903c2a745a220cfb3c43cd520f55f44bf
bytes32 constant TWENTY_SIX_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x1bdded415724018275c7fcc2f564f64db01b5bbeb06d65700564b05c3c59c9e6)
);

uint256 constant THIRTY_TWO_LEVELS = 32;
/// @dev Root of the binary merkle THIRTY_TWO_LEVELS tree with ZERO_VALUE leafs
// Level 26: TWENTY_SIX_LEVEL_EMPTY_TREE_ROOT
// Level 27: 0x038acf368a174e10c45a64161131c0f93faf2f045ff663acbef804eb5644aad7
// Level 28: 0x1b3ecbe4131d8d52d60b91ec8e13d5fc82235232bb43007d54cda6b50d932d6f
// Level 29: 0x1b0b9059f431d38a66c82317d9ed1b744c439f10193ae44bcf519fe6e1766b65
// Level 30: 0x240867e8bb31d6b8057f5ab067dc0bd1c4ba64a42258963ec45b7b4773ce5838
// Level 31: 0x2310e5b3543ea766ecaec53003d0e1b73f19a149409190d00561da7090a2c5cb
bytes32 constant THIRTY_TWO_LEVEL_EMPTY_TREE_ROOT = bytes32(
    uint256(0x24ab16594d418ca2e66ca284f56a4cb7039c6d8f8e0c3c8f362cf18b5afa19d0)
);
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/contracts/protocol/v1/trees/facets/ZZonesRegistry.sol": {
      "PoseidonT3": "0xd98cb2645ed5c3b41f270299781634892630fb41"
    }
  },
  "optimizer": {
    "runs": 800,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.